HTML and CSS Reference
In-Depth Information
Figure 13.2 When the user clicks the button, the onClick event is activated (left);
when the page is refreshed or exits, the onUnload event is activated (right).
13.2.3 Return Values
Sometimes the event handler's return value is necessary if a certain action is to proceed.
The browser's default actions can be suppressed by returning a false value, or a form's sub-
mission can be completed by sending back a true value. For example, if the onSubmit han-
dler gets a true value back from a function or method, then a form may be submitted to
the server, and if not, the form will be stopped. In Chapter 11, “Working with Forms and
Input Devices,” we saw that when validating a form, return values are used. Example 13.3
illustrates these return values.
EXAMPLE 13.3
<html>
<head><title>An HTML Form and the onSubmit Event Handler</title>
<script type="text/javascript">
1
function checkForm(yourinfo){
2
if(yourinfo.namestring.value == "" ||
yourinfo.namestring.value == null){
// Check for an empty string or null value
3
alert("Please type in your name");
4
return(false);
}
else{
5
return(true);
}
}
</script>
</head>
<body><big>
<b>
6
< form name="info" action="/cgi-bin/bookstuff/form1.cgi"
method="post"
7
onSubmit="return checkForm(document.info)">
<br /><br />
Continues
 
 
Search WWH ::




Custom Search