Return the id of the form containing the <input type="submit"> element:
var x = document.getElementById("mySubmit").form.id;
Click the button to display the id of the form the Submit button belongs to.
<!DOCTYPE html> <html> <body> <form id="myForm"> First name: <input type="text" name="fname"> <input type="submit" id="mySubmit"> </form>/*from w w w . j a v a 2 s . c o m*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("mySubmit").form.id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The form property returns a reference to the form that contains the submit button.
This property returns a form object on success.
This property is read only.
If the submit button is not in a form, null is returned