Java Reference
In-Depth Information
}
function txtAge_onblur()
{
var txtAge = document.form1.txtAge;
if (isNaN(txtAge.value) == true)
{
alert(“Please enter a valid age”);
txtAge.focus();
txtAge.select();
}
}
function txtName_onchange()
{
window.status = “Hi “ + document.form1.txtName.value;
}
</script>
</head>
<body>
<form action=”“ name=”form1”>
Please enter the following details:
<p>
Name:
<br />
<input type=”text” name=”txtName” onchange=”txtName_onchange()“ />
</p>
<p>
Age:
<br />
<input type=”text” name=”txtAge” onblur=”txtAge_onblur()“
size=”3” maxlength=”3” />
</p>
<p>
<input type=”button” value=”Check Details”
name=”btnCheckForm” onclick=”btnCheckForm_onclick()“>
</p>
</form>
</body>
</html>
After you've entered the text, save the fi le as ch7_examp4.htm and load it into your web browser.
In the text box shown in Figure 7-5, type your name. When you leave the text box, you'll see Hi yourname
appear in the status bar at the bottom of the window.
Enter an invalid value into the age text box, such as aaaa , and when you try to leave the box, it'll tell
you of the error and send you back to correct it.
Finally, click the Check Details button and both text boxes will be checked to see that you have com-
pleted them. If either is empty, you'll get a message telling you to complete the whole form, and it'll
send you back to the box that's empty.
If everything is fi lled in correctly, you'll get a message thanking you, as shown in Figure 7-5.
Search WWH ::




Custom Search