xxxxxxxxxx
// Assuming the checkbox has an id attribute of 'myCheckbox'
var checkbox = document.getElementById('myCheckbox');
if (checkbox.checked) {
console.log('Checkbox is checked');
} else {
console.log('Checkbox is not checked');
}
xxxxxxxxxx
<input type="checkbox" name="free" value="mon09" onClick="this.checked=!this.checked;">
xxxxxxxxxx
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Checkbox</title>
</head>
<body>
<label for="accept">
<input type="checkbox" id="accept" name="accept" value="yes"> Accept
</label>
<script>
const cb = document.querySelector('#accept');
if (cb){
console.log('checked');
}
else{
console.log('not checked');
}
</script>
</body>
</html>
xxxxxxxxxx
<script>
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).is(":checked")){
console.log("Checkbox is checked.");
}
else if($(this).is(":not(:checked)")){
console.log("Checkbox is unchecked.");
}
});
});
</script>