javascript check checkbox code example
Example 1: javascript check uncheck checkbox
document.getElementById("myCheckBoxID").checked = true; // Check
document.getElementById("myCheckBoxID").checked = false;// Uncheck
Example 2: dom check a checkbox
document.getElementById("myCheck").checked = true;
Example 3: how to check if input is checked javascript
const cb = document.getElementById('accept');
console.log(cb.checked);
Example 4: check if checkbox is checked javascript
<script type=text/javascript>
function validate(){
if (remember.checked == 1){
alert("checked") ;
} else {
alert("You didn't check it! Let me check it for you.")
}
}
</script>
<input id="remember" name="remember" type="checkbox" onclick="validate()" />