Section 25.132. Form: a form in an HTML document


25.132. Form: a <form> in an HTML document

DOM Level 2 HTML: Node Element HTMLElement Form

25.132.1. Properties


readonly HTMLCollection elements

An array (HTMLCollection) of all elements in the form. See Form.elements[].


readonly long length

The number of form elements in the form. This is the same value as elements.length.

In addition to these properties, Form also defines the properties in the following table, which correspond directly to HTML attributes:

Property

Attribute

Description

String acceptCharset

acceptcharset

Character sets the server can accept

String action

action

URL of the form handler

String enctype

enctype

Encoding of the form

String method

method

HTTP method used for form submission

String name

name

Name of the form

String target

target

Frame or window name for form submission results


25.132.2. Methods


reset( )

Resets all form elements to their default values.


submit( )

Submits the form to a web server.

25.132.3. Event Handlers


onreset

Invoked just before the elements of the form are reset.


onsubmit

Invoked just before the form is submitted. This event handler allows form entries to be validated before being submitted.

25.132.4. HTML Syntax

A Form object is created with a standard HTML <form> tag. The form contains input elements created with <input>, <select>, <textarea>, and other tags:

 <form     [ name="form_name" ]       // Used to name the form in JavaScript     [ target="window_name" ]   // The name of the window for responses     [ action="url" ]           // The URL to which the form is submitted     [ method=("get"|"post") ]  // The method of form submission     [ enctype="encoding" ]     // How the form data is encoded     [ onreset="handler" ]      // A handler invoked when form is reset     [ onsubmit="handler" ]     // A handler invoked when form is submitted > // Form text and input elements go here </form> 

25.132.5. Description

The Form object represents a <form> element in an HTML document. The elements property is an HTMLCollection that provides convenient access to all elements of the form. The submit( ) and reset( ) methods allow a form to be submitted or reset under program control.

Each form in a document is represented as an element of the Document.forms[] array. Named forms are also represented by the form_name property of their document, where form_name is the name specified by the name attribute of the <form> tag.

The elements of a form (buttons, input fields, checkboxes, and so on) are collected in the Form.elements[] array. Named elements, like named forms, can also be referenced directly by name: the element name is used as a property name of the Form object. Thus, to refer to an Input element named phone within a form named questionnaire, you might use the JavaScript expression:

 document.questionnaire.phone 

25.132.6. See Also

Input, Select, Textarea; Chapter 18




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net