I have a group of checkboxes (id = "first" id = "second") and the main checkbox (id = "main").
<input type='checkbox' id="main_button" onclick="Indeterminate()"><label for="main_button">Main checkbox of group</label>
<input type='checkbox' id="first" onclick="Indeterminate()"><label for="first">First thing</label>
<input type='checkbox' id="second" onclick="Indeterminate()"><label for="second">Second thing</label>
If one or more of the group checkbox checked then the main have indeterminate condition. If all checked then the main checkbox have also checked condition.
function Indeterminate() {
if (document.getElementById('first').checked || document.getElementById('second').checked) {
document.getElementById('main_button').indeterminate = true;
} else if (document.getElementById('first').checked && document.getElementById('second').checked) {
document.getElementById('main_button').checked;
} else {
document.getElementById('main_button').indeterminate = false;
}
}
In my IF ELSE statement, conditions IF and ELSE works, but there is something wrong with ELSE IF. Probably doing a simple mistake or? Thank you!
Aucun commentaire:
Enregistrer un commentaire