Return the id of the form containing the <input type="number"> element:
var x = document.getElementById("myNumber").form.id;
Click the button to return the id of the form the number field belongs to.
<!DOCTYPE html> <html> <body> <form id="myForm"> <input type="number" id="myNumber" value="2"> </form>//from www .j a va 2s . co m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myNumber").form.id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The form
property returns a reference to the form containing the number field.
This property returns a form object on success.
This property is read only.
If the number field is not in a form, null is returned