HTML and CSS Reference
In-Depth Information
Type your name here:
<input type="text" name="namestring" size="50" />
<br /><br />
<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
The function called checkForm() has one argument, yourinfo , which is a reference
to the form defined on line 6.
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
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.
If false is returned from this function, the form will not be submitted to the server.
If true is returned from this function, the form will be submitted to the server.
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.
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, (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 .
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.
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.
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