I have 5 checkboxes in each row. The first one is 'ALL'. I am trying to see if any of the others are disabled. So, if somebody clicks on 'ALL' checkbox, I need to make sure the disabled ones are not checked. This is what I have:
("input[name^=all_]").each(function() {
var input = $(this);
var name = input.attr('name');
var num = /\d+$/.exec(name)[0];
$(this).click(function() {
if ($('"#G"+num').attr('disabled',false)) {
$("#G"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ($('"#E"+num').attr('disabled',false)) {
$("#E"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ($('"#W"+num').attr('disabled',false)) {
$("#W"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ($('"#S"+num').attr('disabled',false)) {
$("#S"+num).attr('checked', $("#all_"+num).is(':checked'));
}
});
});
The thing is, the disabled ones still gets checked once I click on 'ALL'. what am i doing wrong? thanks in advance.
this works:
if ( !$("#G"+num).is(':disabled') ) {
$("#G"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ( !$("#E"+num).is(':disabled')) {
$("#E"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if ( !$("#W"+num).is(':disabled') ) {
$("#W"+num).attr('checked', $("#all_"+num).is(':checked'));
}
if (!$("#S"+num).is(':disabled')) {
$("#S"+num).attr('checked', $("#all_"+num).is(':checked'));
}
});
To check all except disabled
$('input:checkbox:not(:disabled)').attr('checked','checked');
To uncheck all except disabled
$('input:checkbox:not(:disabled)').removeAttr('checked');
Use jQuery's ":disabled" filter instead of accessing the 'disabled' attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With