Announcement

Check all check box on the click of a single check box.

Following is the code to select all the check boxes on the click of a single check box.


$("input[name='checkboxes']").click(function () {
if ($("input[name='checkboxes']").length == $("input[name='checkboxes']:checked").length) {
$("#checkAll").attr("checked", "checked");
}
else {
$("#checkAll").removeAttr("checked");
}
});

$("#checkAll").click(function () {
$("input[name='checkboxes']").attr("checked", this.checked);
});


checkboxes is the name given to all the check boxes that need to be checked on the click of a single check box.

checkAll is the ID of the single check box on the click of which all check boxes will get checked/unchecked.

No comments: