Checkbox formProperty
Checkbox Object
Definition and Usage
The form property returns a reference to the form containing the checkbox.
This property returns the form object.
Syntax
checkboxObject.form
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the form property
Example
Example
The following example returns the id of the form to which the checkbox belongs:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myCheck").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
<input type="checkbox" id="myCheck">Do you like summer?
</form>
<button type="button" onclick="displayResult()">Show the form ID containing the checkbox</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myCheck").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
<input type="checkbox" id="myCheck">Do you like summer?
</form>
<button type="button" onclick="displayResult()">Show the form ID containing the checkbox</button>
</body>
</html>
Try it Yourself »
Checkbox Object Other Extensions