JavaScript » Objects » Form

Forms allow us to prompt a user for input using elements such as radio buttons, checkboxes and selection lists. Data gathered in this manner can then be posted to a server for processing. A form is created by enclosing HTML controls and other elements within <form></form> tags. A page can contain as many forms as required, but they cannot be overlapping or nested (the closing </form> tag of a form must precede the opening tag of any subsequent form).



Syntax: object.action = URL

This property specifies the URL address to which the data gathered by the form will be submitted. An email address can also be specified using the '' syntax.


Syntax: Object.constructor

This specifies a function to create an object's property and is inherited by all objects from their prototype.


Syntax: object.elements

This property is an array containing an object for each element on the form. These objects (checkboxes, radio buttons, etc.) are added to the array in the order that they appear in the document's source code.


Syntax: object.encoding

This property sets the MIME type that is used to encode the data gathered by the elements in a form for submission when using the post method. This property initially contains a string reflecting the enctype attribute of the form tag, but using encoding will override this.


Syntax: object.length

This property returns the number of elements in a form.


Syntax: object.method

This property is a string specifying how information input in a form is submitted to the server. This should return either 'get', which is the default, or 'post'.



This property sets or returns the name of the form. Initially contains the name attribute of the <form> tag.


Syntax: = value

This allows the addition of properties and methods to any object.



This property sets or returns the target window that responses are sent to after submission of a form.



Syntax: Object.eval(string)

The eval method is deprecated as a method of Object, but is still used as a high level function. It evaluates a string of JavaScript in the context of an object.


Syntax: object.handleEvent"event"

This method invokes the event handler for the specified event.


Syntax: object.reset( )

This method resets the default values of any elements in a form. Emulates the clicking of a Reset button (athough it is not necessary to have a reset button in a form to use this method).


Syntax: object.submit( )

This method submits a Form. This is the same as clicking a Submit button.


Syntax: Object.toSource()

The toSource method returns a literal representing the source code of an object. This can then be used to create a new object.


Syntax: Object.toString()

The toString method returns a string representing a specified object.


Syntax: Object.unwatch(property)

This method removes a watchpoint set for an object and property name with the watch method.


Syntax: Object.valueOf()

This method returns a primitive value for a specified object.


Syntax:, handlerfunction)

This method adds a watchpoint to a property of the object.

See Also: