Reputation: 4038
I have a couple of checkboxes and a status box that tells you if at least 1 of the checkboxes are checked.
I also have a check All/None checkbox which works in toggling the checkboxes but it is not triggering the change event that is assigned to each of the checkboxes so the status never gets updated if the check All/None checkbox is used.
Here is my implementation:
http://jsfiddle.net/axl163/Fckvd/1/
Upvotes: 7
Views: 4835
Reputation: 79830
Any changes to an input element through a script WILL NOT trigger onchange
event.
Alternatively you can trigger the change()
while updating the changing the input like below,
$(this).prop("checked", status).change();
Full code:
function toggleChecked(status) {
$(".chkbx").each( function() {
$(this).prop("checked", status).change();
});
}
Also use .prop
instead of .attr
Upvotes: 6
Reputation: 87073
function toggleChecked(status) {
$(".chkbx").each( function() {
$(this).prop("checked", status).change(); // you have to trigger the event
});
}
Upvotes: 15