PROBLEM - Javascript - Check / Uncheck All group checkboxes

Problem


Check / Uncheck all for checkboxes.


Solution Code

Name all checkboxes in a group with a single name (  checkBoxGroup ) in our case.

function checkAll(masterBox){
   var checkboxes = document.getElementsByName("checkBoxGroup");
     if (masterBox.checked) {
         for (var i = 0; i < checkboxes.length; i++) {
                  checkboxes[i].checked = true;
         }
     } else {
         for (var i = 0; i < checkboxes.length; i++) {
             console.log(i)
                checkboxes[i].checked = false;

         }
     }
}