You are here: Reference > JavaScript > client-side > HTML DOM > properties > length (form, keygen, select)

length property (form, keygen, select)

Browser support:
Returns the number of form controls in a form element or the number of options in a select or keygen element.
For the list of form controls, see the page for the form element.

Syntax:

object.length;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Integer that represents the number of objects.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the length property:
<head>
    <script type="text/javascript">
        function GetLength () {
            var elemLength = document.getElementById ("myForm").length;
            alert ("There are " + elemLength + " form controls in the form.");
        }
    </script>
</head>
<body>
    <form id="myForm">
        <input type="radio" name="sex" id="radio_female" value="female" checked="checked"/> <label for="radio_female">female</label>
        <br />
        <input type="radio" name="sex" id="radio_male" value="male" /> <label for="radio_male">male</label>
        <br /><br />
        <input type="submit" value="Register" disabled="disabled" />
    </form>
    
    <br /><br />
    <button onclick="GetLength ();">Get form length!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content