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).

Properties

action

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 'mailto:anybody@anywhere.com' syntax.

constructor

Syntax: Object.constructor

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

elements

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.

encoding

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.

length

Syntax: object.length

This property returns the number of elements in a form.

method

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'.

name

Syntax: object.name

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

prototype

Syntax: Object.prototype.name = value

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

target

Syntax: object.target

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

Methods

eval

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.

handleEvent

Syntax: object.handleEvent"event"

This method invokes the event handler for the specified event.

reset

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).

submit

Syntax: object.submit( )

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

toSource

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.

toString

Syntax: Object.toString()

The toString method returns a string representing a specified object.

unwatch

Syntax: Object.unwatch(property)

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

valueOf

Syntax: Object.valueOf()

This method returns a primitive value for a specified object.

watch

Syntax: Object.watch(property, handlerfunction)

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

See Also: