HTML and CSS Reference
In-Depth Information
EXAMPLE
11.26
Type your name here:
8
<input type="text"
name="namestring"
size="50">
</p>
9
<input type="submit" value="Submit"
/>
<input type="reset" value="Clear" />
</big>
</form>
</body>
</html>
EXPLANATION
1
The function called
checkForm()
has one parameter,
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 he presses OK, he 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
ac-
tion
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 is an attribute of the HTML
<form>
tag. It is triggered when
the user clicks the Submit button. The event handler is a function called
check-
Form()
. Its argument is
this,
same as
document.forms[0]
). The
return
keyword is
required when using the
onSubmit
event handler. One of two values will be re-
turned: 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 11.46.