Object: HTMLFormElement
The HTMLFormElement object represents a <form> element in an HTML document.
The <form> element specifies a form that gathers information from the user. Users can submit a form by using the <submit> input element. After a submission, the form collects the names and values of enclosed <select>, <input>, and <textarea> elements and submits the query as part of the request (GET) or as post data (POST).
HTMLFormElement properties
Property name |
Type |
Description |
Status |
Availability |
|---|---|---|---|---|
acceptCharset |
String |
Specifies a list of valid character sets for form data. |
writable |
4.6.0 |
action |
String |
Specifies a URI to which the form is submitted. |
writable |
4.6.0 |
elements |
Returns an index of the form control elements contained within the form. Index positions begin at 0 and continue to HTMLCollection.length-1. Image buttons (<input> elements for which type="image") are excluded from the collection. |
read only |
4.6.0 |
|
enctype |
String |
Specifies the content type the form data is encoded with. |
writable |
4.6.0 |
length |
int |
Returns the number of form control elements contained within the form. |
read only |
4.6.0 |
method |
String |
Specifies the HTTP method used to send the data to the server. |
writable |
4.6.0 |
name |
String |
Specifies a unique name for the form. |
read only |
4.6.0 |
target |
String |
Specifies where the target document is opened. |
writable |
4.6.0 |
HTMLFormElement methods
Method name |
Description |
Availability |
|---|---|---|
Returns the form control element at he specified index of the collection. |
4.7.1 or later |
|
Retrieves the form control element or elements whose id or name attributes that match the given name from the collection. |
4.7.1 or later |
|
Restores the default values to the form element. |
4.6 or later |
|
Submits the current values of the form element. |
4.6 or later |
Method: HTMLFormElement.item()
The item() method returns the element that is located at the specified index of the HTMLFormElement.elements collection. Image buttons (<input> elements for which type="image") are not included in the collection, and are therefore not returned with this method.
This method is equivalent to invoking HTMLFormElement.elements[ index ].
Parameters
Parameter |
Type |
Description |
|---|---|---|
index |
int |
Specifies the index position of the element to be returned. Valid values are from 0 and HTMLFormElement.elements-1. |
Method: HTMLFormElement.namedItem()
Syntax
The namedItem() method retrieves the element or elements that contain id or name attributes that match the specified name from the HTMLFormElement.elements collection. Image buttons (<input> elements for which type="image") are not included in the collection, and are therefore not returned with this method.
This method is equivalent to invoking HTMLFormElement.elements["name"].
HTMLFormElement.namedItem( name )
Return values
This method returns the element that has an id or name attribute of name, or null if no element with the specified name exists within the HTMLFormElement.elements collection. If multiple elements match, this method returns a NodeList object that contains all the matching elements.