Form Handling
Form Handling
JavaScript provides access to the forms within an HTML document through the Form
object known as HTMLFormElement in the DOM. Which is a child of the Document
Object.
Properties
Properties Value Description
accept-charset UTF-8 Specifies the charset used in the submitted form (default: the page
charset).
action URL Contains a URL that defines where to send the data after submitting
the form
autocomplete On (default) Determines that the browser retains the history of previous values.
Off
enctype specifies how the browser encodes the data before it sends it to the
server. (default: is url-encoded).
encoding Holds the value of the enctype attribute, which usually contains either
application/x-www-form-urlencoded value or the multipart/form-data
value (in the case of file upload)
elements[ ] An array of DOM elements that correspond to the interactive form
fields within the form
Properties
Properties Value Description
length The number of form field with a given form tag. Should bt the same as
elements.length
Specifies how to send the form data to a web server. The data can be
method GET (default) sent as URL variables, by using the get method or as HTTP post, by
POST using the post method
name name Specifies a name used to identify the form
novalidate novalidate Specifies that the browser should not validate the form.
_self (default)
target _blank Specifies the target of the address in the action attribute
_parent
_top
framename
Methods
Method Description
checkValidity ( ) Returns a true or flase value indicating whether or not all the fields in
the form are in a valid state.
reset ( ) Returns all form fields to their initial state.
submit ( ) Submits the form to the URL specified in the form’s action attribute
Events: -
• onreset
• onsubmit