Javascript examples for DOM HTML Element:Form
The elements collection returns all elements in a form sorted as they appear in the source code.
Property | Description |
---|---|
length | number of elements in the <form> element. |
Method | Description |
---|---|
[index] | element in <form> with the specified index (starts at 0). |
item(index) | element in <form> with the specified index (starts at 0). |
namedItem(id) | element in <form> with the specified id. |
An HTMLFormsControlCollection Object, representing all elements in a <form> element.
The following code shows how to Find out how many elements there are in a specified <form> element:
<!DOCTYPE html> <html> <body> <form id="myForm" action="/action_page.php"> 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>//from ww w . ja va 2 s.c om <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myForm").elements.length; document.getElementById("demo").innerHTML = "Found " + x + " elements in the form."; } </script> </body> </html>