vendredi 28 février 2020

How to select all checkbox when i checked all check boxes

I want to select all checkbox checked when i select all checkboxes in my dropdown menu. I am a beginner js developer need help. This is my js code

var expanded = false;
function showCheckboxes() {
var checkboxes = document.getElementById("checkboxes");
if (!expanded) {
checkboxes.style.display = "block";
expanded = true;
} else {
checkboxes.style.display = "none";
expanded = false;
}
}
var selectallBox = document.getElementById('selectall');
var checkBoxes = document.querySelectorAll('.select-me');
selectallBox.addEventListener('click', function() {

for (var i = 0; i < checkBoxes.length; i++) {
    if (checkBoxes[i] != selectallBox)
        checkBoxes[i].checked = selectallBox.checked;
}


})
for (var i = 0; i < checkBoxes.length; i++) {
   checkBoxes[i].addEventListener('click', function() {

    selectallBox.checked = false; 
})
}
document.querySelector('.close-check-box').addEventListener('click' , function(){
checkboxes.style.display = 'none'
})

This is my js fiddle: https://jsfiddle.net/b9ueL3fw/




Aucun commentaire:

Enregistrer un commentaire