Javascript examples for DOM:Document forms
Document forms Collection item(index) - Get the id of the first <form> element (index 0) in the document:
<!DOCTYPE html> <html> <body> <form id="myCarForm"> Favorite Car: <input type="text" name="fname" value="Volvo"> </form>//from ww w. j a v a2 s .c om <form id="myColorForm"> Favorite Color: <input type="text" name="favcolor" value="Blue"> </form> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.forms.item(0).id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>