JavaScript form Object
-
JavaScript has a form object to deal with forms.
-
It is an attribute of the document object.
-
There are two ways to access the form object:
-
By name: document.formName
-
By array: document.form[n]
-
The form object has properties:
-
action - same as ACTION in form tag; where the information
will be submitted.
-
encoding - MIME type, text, image, etc. You probably
won't need this.
-
length - Number of elements on form. You can use this later
when accessing the elements.
-
method - GET, POST, or other.
-
target - window in which the results will be displayed.
-
It also has methods, just like the two default button types in a form:
-
submit() - submits the form to the ACTION URL via the
POST method.
-
reset() - clears all fields.
-
And event handlers
-
onSubmit - called when form is submitted by user. How
could you use this?
-
return true to allow form to be submitted,
-
false to prevent submission.
-
onReset - called when form is reset by user. How
could you use this?
Form Elements
Home
Internet II: Day 4