Javascript examples for DOM HTML Element:Button
The form property returns the form containing the button.
This property is read only.
A reference to the form element containing the button. If the button is not in a form, null is returned
The following code shows how to return the id of the form the button belongs to:
<!DOCTYPE html> <html> <body> <form id="myForm"> <button id="myBtn" type="button" onclick="myFunction()">Test</button> </form>// w w w . j a v a 2s. c o m <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myBtn").form.id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>