The HTMLFormElement.length
read-only property returns the number of controls in the <form>
element. You can access the list of the form's controls using the elements
property.
This includes both elements that are descendents of the <form>
element as well as elements that are made members of the form using their form
property.
The elements included by HTMLFormElement.elements
and HTMLFormElement.length
are the following:
<button>
<fieldset>
<input>
(with the exception that any whosetype
is"image"
are omitted for historical reasons)<object>
<output>
<select>
<textarea>
No other elements are included in the list returned by elements
, which makes it an excellent way to get at the elements most important when processing forms.
Syntax
numControls = form.length;
Value
numControls
is the number of form controls within the <form>
. This is the same as the number of the elements in the HTMLFormControlsCollection
returned by the elements
property.
Example
if (document.getElementById('form1').length > 1) { // more than one form control here }
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'HTMLFormElement: length' in that specification. |
Living Standard |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
length | Chrome Full support Yes | Edge Full support 12 | Firefox Full support Yes | IE ? | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support Yes | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown