I'm working on a simple function that involves 3 checkboxes. The goal is to disable the button if all checkboxes are unchecked, and enable it only when all three checkboxes are checked.
function checkAll() {
var checkbox1 = document.getElementById("ch1");
var checkbox2 = document.getElementById("ch2");
var checkbox3 = document.getElementById("ch3");
var submitBtn = document.getElementById("btn");
if (checkbox1.checked && checkbox2.checked && checkbox3.checked){
return submitBtn.disabled = false;
}
else {
return submitBtn.disabled = true;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
</head>
<body>
<input type="checkbox" id="ch1" >
<input type="checkbox" id="ch2" >
<input type="checkbox" id="ch3" >
<button onclick="checkAll()" id="btn">Submit</button>
</body>
<script>
</script>
</html>