Java Reference
In-Depth Information
The square bracket notation can be used instead (again, this is useful if there are any nam-
ing clashes with existing property and method names, or if the name is an invalid variable
name):
var input = form['searchBox']
Form Properties and Methods
Form objects have a number of useful properties and methods that can interact with the
form.
The
form.submit()
method will submit the form automatically. Note that submitting
a form using this method won't trigger a form "submit" event; that is covered in the next
section.
A form can be submitted manually by the user employing a button or input element with a
type attribute of
submit
, or even an input element with a
type
attribute of
image
:
<button type="submit">Submit</button>
<input type="submit" value="Submit">
<input type="image" src="button.png">
The
form.reset()
method will reset all the form controls back to their initial values
specified in the HTML.
A button with the
type
attribute of
reset
can also be used to do this without the need
for additional scripting:
<button type="reset">Reset</button>
Warning: Avoid Reset Buttons
Reset buttons are generally considered poor for usability, as they are too
easy to click and then wipe out all the data that's been entered. So think very
carefully before using one in a form.
