Chapter 6. Scripting Events
A graphical user interface constantly monitors the computer’s activity for signs of life from devices such as the mouse, keyboard, serial port, and so on. Programs are written to respond to specific actions, called events, and run some code based on numerous conditions associated with the event. For example, was the Shift key held down while the mouse button was clicked? Where was the text insertion pointer when a keyboard key was pressed? As you can see, an event is more than the explicit action initiated by the user or system—an event also has information associated with it that reveals more details about the state of the world when the event occurred.
In a Dynamic HTML page, you can use a scripting language such as JavaScript (or VBScript in Internet Explorer), to instruct a visible element to execute some script statements when the user does something with that element. The bulk of scripts you write for documents concern themselves with responding to user and system actions after the document has loaded. In this chapter, we’ll examine the events that are available for scripting and discuss how to associate an event with an object. We’ll also explore how to manage events in the more complex and conflicting event models of the Version 4 browsers.
Basic Events
Events have been scriptable since the earliest scriptable browsers. The number and granularity of events have risen with the added scriptability of each browser generation. The HTML 4.0 recommendation ...
Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.