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:

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

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge ? Firefox Full support YesIE ? Opera Full support YesSafari ? WebView Android ? Chrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Contributors to this page: connorshea, Sheppy, teoli, kscarfone, ethertank, jswisher, Mgjbot, George3, Dria
Last updated by: connorshea,