Form lengthProperty
Form Object
Definition and Usage
The length property returns the number of elements in the form.
Syntax
formObject.length
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the length property.
Example
Example
The following example returns the number of elements in the form:
<html>
<body>
<form id="frm1" action="form_action.html">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
<input type="submit" value="Submit">
</form>
<script>
document.write(document.getElementById("frm1").length);
</script>
</body>
</html>
<body>
<form id="frm1" action="form_action.html">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
<input type="submit" value="Submit">
</form>
<script>
document.write(document.getElementById("frm1").length);
</script>
</body>
</html>
The output of the above example is:
3
Try it Yourself »
More Examples
Get the value of each element in the form
Form Object Other Extensions