Categories
JavaScript

Javascript to select all / unselect all checkboxes based on the Prototype library

// Select / unselect all functionality:
function toggleCheckboxes() {
if ($F(’select_all’) == ‘on’){
document.getElementsByClassName(’checkboxes_class’).each(
function(s) {
s.checked = true;
}
);
} else {
document.getElementsByClassName(’checkboxes_class’).each(
function(s) {
s.checked = false;
}
);
}
}

select_all is the name of the checkbox you use for the toggling.  Since you are using a class name to identify all the elements on your page that are to be selected / unselected, you need to add to all the checkboxes to be affected with this functionality

Leave a Reply

Your email address will not be published. Required fields are marked *