HTML and CSS Reference
In-Depth Information
Table 13.1 JavaScript Event Handlers and What They Do (continued)
Event Handler
What It Affects
When It Happens
onMouseOver
Links (and images within links)
When the mouse moves over a link. Return
true to prevent link from showing in the status
bar.
onMove
Windows
When the browser window is moved.
onReset
Forms reset button
When the form's Reset button is clicked.
Return false to stop reset.
onResize
Windows
When the browser window changes size.
onSelect
Form elements
When a form element is selected.
onSubmit
Forms
When you want to send a form to the server.
Return false to stop submission to the server.
onUnload
Body, framesets
After the document or frameset is closed or
reset.
13.2.2 Setting Up an Event Handler
There are two parts to setting up an event handler:
1. The event handler is assigned as an attribute of an HTML tag such as a document,
form, image, or link. If you want the event to affect a document, then it would
become an attribute of the <body> tag; if you want the event to affect a button,
then it would become an attribute of the form's <input> tag; and if you want the
event to affect a link, then it would become an attribute of the <a href> tag. For
example, if the event is to be activated when a document has finished loading, the
onLoad event handler is used, and if the event happens when the user clicks an
input device, such as a button, the onClick event handler is fired up.
<body onLoad ="alert('Welcome to my Web site');">
<form>
<input type="button"
value="Tickle me "
onClick ="alert('Hee hee ho hee');" />
</form>
</body>
2. The next step is to register or assign a value to the event handler. The value can
be a built-in method such as alert() or confirm() , a user-defined function, or a
string of JavaScript statements. Although the event handler is an attribute of an
HTML tag, if a user-defined function is assigned to the event handler, then that
function must be defined either in a JavaScript program or as direct script state-
ments (separated by semicolons).
 
 
Search WWH ::




Custom Search