I have the following code for selecting multiple checkboxes:
$(document).ready(function() {
/* All groups functionality */
$(".allGroups").change(function() {
var checked = this.checked;
if (checked == true) {
$(".group").attr("checked", true);
$(".c").attr("checked", true);
}
if (checked == false) {
$(".group").attr("checked", false);
$(".c").attr("checked", false);
}
})
/* Individual Group functionality */
$(".group").change(function() {
var checked = this.checked;
var number = this.value
var set = '.group-' + number;
$(set).attr("checked", checked);
})
} )
I gave 'contacts' the class c and group-#. Groups get the class group.
The select all checkbox gets .allGroups
Now how do I achieve that the 'select all' checkbox unchecks itself when not everything is checked anymore?
Got a jsFiddle up here: http://jsfiddle.net/nqHtu/1/