O'Reilly logo

Dynamic HTML: The Definitive Reference, 3rd Edition by Danny Goodman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required