HTML and CSS Reference
EXAMPLE 11.27 ( CONTINUED )
<form name="alphachk" onSubmit="return validate(this);">
Enter your first name:
Enter your last name:
13 <input type=submit value="Check it out">
ence to a form object.
The if expression invokes a function, called alpha() , and passes the text object to
it. The first name is validated by the alpha() function. If false is returned, the block
is entered and the user is alerted that he or she did not enter a valid first name. If
this function returns false to the onSubmit handler that invoked it, on line 10, the
form will not be submitted.
As in line 2, the alpha() function is being called, only this time to verify the last
name of the user.
The function called alpha() is defined. All the validation work is done here. This
function will validate that the user entered something in the textbox, and that
what he or she entered is alphabetic characters, and only alphabetic characters,
either uppercase or lowercase.
If the length of characters entered in the text field is not equal to 0, then the block