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 which are included by HTMLFormElement.elements and HTMLFormElement.length are:
<button><fieldset><input> (with the exception that any whose type 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.
numControls = form.length;
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.
if (document.getElementById("form1").length > 1) {
// more than one form control here
}
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | ? | Yes | ? | Yes | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | ? | Yes | ? | Yes | Yes | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/length