jquery - check all/ uncheck all checkboxes js -
i have little problem , don't how prepare it, if have checkboxes selected appear "deselect all" if deselect 1 or 2 want "select all" appear again, issue if select every checkbox , start manually unchecking 1 1 suppose activate select again, if press select uncheck instead of check all.
this part of html code:
<input type="button" class="btn-primary btn-mini" id="check1" value="check all" /> <input type="hidden" id="ischkd" value="true" /> <input type="checkbox" name="" value="" class="cb1-element"> 751 <input type="checkbox" name="" value="" class="cb1-element"> 752 <input type="checkbox" name="" value="" class="cb1-element"> 753 <input type="checkbox" name="" value="" class="cb1-element"> 754
my js:
$('#check1').toggle(function(){ $('.cb1-element').attr('checked','checked'); $(this).val('uncheck all'); $('#ischkd').val(true); },function(){ $('.cb1-element').removeattr('checked'); $(this).val('check all'); $('#ischkd').val(false); }) $('.cb1-element').change(function(){ if($('#ischkd').val() == false){ $('#check1').val('uncheck all'); $('#ischkd').val(true); }else{ $('#check1').val('check all'); $('#ischkd').val(false); } });
$('#check1').click(function(){ if($('#ischkd').val() == 'true'){ $('.cb1-element').attr('checked','checked'); $(this).val('uncheck all'); $('#ischkd').val('false'); } else{ $('.cb1-element').removeattr('checked'); $(this).val('check all'); $('#ischkd').val('true'); } }); $('.cb1-element').change(function(){ var = $('input.cb1-element').length; var checked = $('input.cb1-element:checked').length; if(all == checked){ $('#check1').val('uncheck all'); $('#ischkd').val('false'); }else{ $('#check1').val('check all'); $('#ischkd').val('true'); } });
working jsfiddle here http://jsfiddle.net/c9tw2/18/
jquery checkbox uncheck
No comments:
Post a Comment