checkbox js code example
Example 1: oncheck checkbox javascript
<input type='checkbox' onchange='handleChange(this);'> Checkbox
function handleChange(checkbox) {
if(checkbox.checked == true){
document.getElementById("submit").removeAttribute("disabled");
}else{
document.getElementById("submit").setAttribute("disabled", "disabled");
}
}
Example 2: commande checkbox html
<!doctype html>
<html>
<body>
<input type="checkbox">
<input type="radio">
</body>
</html>
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()" />