jquery - single checkbox updates state of muliple checkboxes -
i have group of checkboxes, 1 of them has label of 'none'. when ticked, i'd others disabled. if 'none' checkbox unchecked, checkboxes disabled, enabled again.
i have following code:
$(document).ready(function(){ $("#select_none").click(function() { $('#select_blue').attr('disabled', true); $('#select_green').attr('disabled', true); $('#select_red').attr('disabled', true); $('#select_black').attr('disabled', true); $('#select_white').attr('disabled', true); $('#select_yellow').attr('disabled', true); $('#select_pink).attr('disabled', true); }); });
this disables if checkbox has been clicked on, doesn't toggle.
could me toggle functionality?
try code
$(document).ready(function(){ $("#select_none").click(function() { if(this.checked) { $('#select_blue').attr('disabled', true); $('#select_green').attr('disabled', true); $('#select_red').attr('disabled', true); $('#select_black').attr('disabled', true); $('#select_white').attr('disabled', true); $('#select_yellow').attr('disabled', true); $('#select_pink').attr('disabled', true); }else { $('#select_blue').removeattr('disabled'); $('#select_green').removeattr('disabled'); $('#select_red').removeattr('disabled'); $('#select_black').removeattr('disabled'); $('#select_white').removeattr('disabled'); $('#select_yellow').removeattr('disabled'); $('#select_pink').removeattr('disabled'); } }); });
Comments
Post a Comment