Javascript: Check / Uncheck All The Checkboxes Of a Certain Group

/*
 * It checks all the checkboxes of a certain group (that shares a name like this: checkboxes[])
 *
 * @param the Javascript Element that contains all the checkboxes of a certain group
 *
 * Example of usage:
 * var checkboxesObj = document.getElementsByName(’checkboxes[]’);
 * selectAllCheckboxes(checkboxesObj);
 */

function checkAllCheckboxes(checkboxesObj)
{
    var checkboxesLength = checkboxesObj.length;
    for(var i = 0; i < checkboxesLength; i++) {
        checkboxesObj[i].checked = true;
    }
}
This entry was posted in HTML / CSS, Javascript. Bookmark the permalink.

Leave a Reply