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