Handling Events

Events are actions that the user performs while visiting your page. Submitting a form and moving a mouse over an image are two examples of events.

JavaScript deals with events using commands called event handlers. An action by the user on the page triggers an event handler in your script. The 12 most common JavaScript event handlers are listed in Table 1.1. We deal with other, more advanced event handlers in Chapter 9.

Table 1.1. Event Handlers
EventWhat it handles
onabortThe user aborted loading the page
onblurThe user left the object
onchangeThe user changed the object
onclickThe user clicked an object
onerrorThe script encountered an error
onfocusThe user made an object active
onloadThe object finished loading
onmouseoverThe cursor ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh 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.