THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Form length Property

Form Object Reference Form Object

Example

Return the number of elements in a form:

var x = document.getElementById("myForm").length;

The result of x will be:

3
Try it yourself »

Definition and Usage

The length property returns the number of elements in a form.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The length property is supported in all major browsers.


Syntax

formObject.length

Technical Details

Return Value: A Number, representing the number of elements in the form

More Examples

Example

Return the value of each element in a form:

var x = document.getElementById("myForm");
var txt = "";
var i;
for (i = 0; i < x.length; i++) {
    txt = txt + x.elements[i].value + "<br>";
}
document.getElementById("demo").innerHTML = txt;
Try it yourself »

Form Object Reference Form Object