Chapter ONLINE SECTION VI. Scripting Events
A graphical user interface constantly monitors the computer’s activity for signs of life from devices such as the mouse, keyboard, network 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 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 for Windows) to instruct a visible element to execute 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. Here we’ll examine 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 within the IE and W3C DOMs.
Event Types
Events have been scriptable since the earliest scriptable browsers. The number and granularity of events have increased with the added scriptability of each browser generation. The HTML 4 and DOM ...
Get Dynamic HTML: The Definitive Reference, 3rd Edition 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.