Checkbox defaultCheckedProperty
Checkbox Object
Definition and Usage
The defaultChecked property returns the default value of the checked attribute.
This property returns true if the checkbox is checked by default, otherwise it returns false.
Syntax
checkboxObject.defaultChecked
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the defaultChecked property
Example
Example
The following example returns the value of the checked attribute:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myCheck").defaultChecked;
alert(x);
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="myCheck" checked="checked">Do you like summer?
</form>
<button type="button" onclick="displayResult()">Is the default checkbox selected?</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myCheck").defaultChecked;
alert(x);
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="myCheck" checked="checked">Do you like summer?
</form>
<button type="button" onclick="displayResult()">Is the default checkbox selected?</button>
</body>
</html>
Try it Yourself »
Checkbox Object Other Extensions