HTML DOM Input Checkbox form Property

HTMLWeb DevelopmentFront End Technology

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 −

 Live Demo

<!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 −

raja
Published on 19-Jul-2019 11:32:31
Advertisements