HTML and CSS Reference
In-Depth Information
EXAMPLE 13.3 ( CONTINUED )
Type your name here:
8
<input type="text" name="namestring" size="50" />
<br /><br />
9
<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
</form>
<big>
</body>
</html>
EXPLANATION
1
The function called checkForm() has one argument, yourinfo , which is a reference
to the form defined on line 6.
2
If the user didn't enter anything into the textbox, the value of the input type will
be null. The expression if(yourinfo.namestring.value == “”) checks for an empty
field.
3
The user didn't enter anything into the textbox. An alert dialog box will appear
on the screen, and after the user clicks OK, he or she will have a chance to fill out
the form again.
4
If false is returned from this function, the form will not be submitted to the server.
5
If true is returned from this function, the form will be submitted to the server.
6
The HTML form starts here. The form, document.forms[0] , is named “info” . The
action attribute contains the URL of the program that will process the form, a CGI
script on the server. The method attribute defines the HTTP method that deter-
mines how the data will be sent to the server.
7
The onSubmit event handler is an attribute of the HTML <form> tag and is trig-
gered when the user clicks the submit button. The event handler is a function
called checkForm() . Its parameter is the name of the form, document.info (also
could use its array name: document.forms[0] ). The return keyword is required
when using the onSubmit event handler. One of two values will be returned: either
true or false .
8
The input type for this form is a text field box. Its name is “namestring” and it can
hold a string of up to 50 characters.
9
The input type is the submit button. When the user clicks this button, the onSub-
mit event handler on line 7 is activated. See Figure 13.3.
13.2.4
JavaScript Object Methods and Events
JavaScript event methods can be used to simulate the event attributes. (See the section
“Unobtrusive JavaScript” in Chapter 15.) An event handler is an attribute of an HTML
 
 
 
Search WWH ::




Custom Search