The HTML DOM Input Checkbox form property returns the form containing the input checkbox.
Syntax
Following is the syntax −
Returning reference to the form object
inputCheckboxObject.form
Example
Let us see an example of HTML DOM Input Checkbox form property −
<!DOCTYPE html> <html> <head> <title>Student Details</title> </head> <body> <form id="Student-Form"> <div> <input type="text" name="fullName" placeholder="eg: John Doe"> Show Form ID: <input id="formID" type="checkbox" name="formID"> </div> </form> <button onclick="getFormID()">Get ID of form containing this Checkbox</button> <div id="showResult"></div> <script> function getFormID(){ var checkboxFilter = document.getElementById("formID"); var showResultDiv = document.getElementById("showResult"); if(checkboxFilter.checked == true){ showResultDiv.textContent = 'Form ID: ' + checkboxFilter.form.id; } else { showResultDiv.textContent = 'Check the checkbox'; } } </script> </body> </html>
Output
This will produce the following output −
Before checking ‘Show Form ID’ checkbox −
After checking ‘Show Form ID’ checkbox −