HTML and CSS Reference
In-Depth Information
EXAMPLE 13.4
<html>
<head><title>Simulation Methods</title></head>
<body bgcolor="yellow">
1
<form name="myform"
2
action="http://localhost/cgi-bin/doit.pl"
method="post">
Enter your name:<br />
<input type="text"
name="namefield"
id="namefield"
size="30"
value="Name: "
3
onFocus="this.select()" />
<p>
Enter your address:<br />
4
<input type="text"
name="addressfield"
id="namefield"
size="30"
value="Address: "
5
onFocus="this.select()" / >
</p><p>
</form>
6 <a href="#" onClick="JavaScript: document.myform.submit();">
Click here to submit your form</a>
</p><p>
7 <a href="#" onClick="JavaScript:document.myform.reset();">
Click here to reset your form</a>
</p>
</body>
</html>
EXPLANATION
1
A form named myform is started.
2
This is the URL where the form will be processed after it is submitted.
3
The onFocus event handler is assigned an event method called select() . For this
textbox, when the mouse cursor is clicked in the box, the onFocus event is trig-
gered and the event is handled by highlighting or selecting the text in the box.
4
Another textbox is defined to hold the user's address.
5
When the cursor is moved into this field, the textbox gets focus and the select()
method is called to highlight this box, as in line 3.
6
A deactivated link is assigned an onClick event handler. When the user clicks the
link, the JavaScript code is executed. The pseudo JavaScript: protocol is followed
by a reference to the form and a submit() method, which causes the form to be
submitted when the user clicks the link. A JavaScript function could also have
Search WWH ::




Custom Search