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