HTML and CSS Reference
In-Depth Information
<a href="#" onClick='alert("This hotlink is out of service!");
return false;'>Click here</a>
or by using the JavaScript : protocol followed by the void operator to guarantee that any
return value from the function will be discarded:
<a href="JavaScript:void(0);" onMouseOver="return changeSeason();"
In either case, the link was not supposed to take the user to another location, but instead
to handle an event or call a function. (Make sure that any function calls in the URL have
been defined.) Another note: If the “#” causes the browser to jump to the top of the page
when the link is clicked, you can add a return false statement inside the onClick handler
to keep the browser from checking the content of the href .
The following simple example uses the onClick event handler with a deactivated link
and the return statement; the display is shown in Figure 13.14.
EXAMPLE 13.12
<html><head><title>Deactivate the hotlink</title></head>
<body>
<center>
<a href="#" onClick='alert("This hotlink is out of service!");
return false;'>Click here</a>
</center>
</body>
</html>
Figure 13.14 The user clicked a deactivated link.
13.6 Handling a Form Event
As discussed in Chapter 11, the document object has a form property. It contains an array
of all the forms that have been defined in the document. Each element of the array is a
form object and the number in the index of the array represents the order in which the
form appeared on the page. The first form would be document.forms[0] . Each form con-
tains elements, also represented as an array. The elements represent the input types of
 
 
Search WWH ::




Custom Search