25.132. Form: a <form> in an HTML documentDOM Level 2 HTML: Node |
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 |
reset( )
Resets all form elements to their default values.
submit( )
Submits the form to a web server.
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.
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>
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
Input, Select, Textarea; Chapter 18