Hour 9. Responding to Events

What You’ll Learn in This Hour

• More on JavaScript’s built-in event handlers

• Adding and removing your own event handlers

• Using event handling for form validation

In this hour you learn what event handling is about and how to write proper cross-browser event handlers for your scripts.

Understanding Event Handlers

To a scripting language seeking to add interactivity to web pages, events are fundamental; the user does something (causes some event to fire), and the page reacts to that event. Therefore JavaScript needs a way of detecting user actions so that it knows how to react appropriately.

There are also some events that aren’t caused directly by user interaction, for example, the window.onload event introduced ...

Get Sams Teach Yourself JavaScript™ in 24 Hours, Fifth 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.