Group checkboxes check/uncheck
I am working on group of checkboxes for check/uncheck. I did solve for that, but I having another issue outside the group of checkboxes.
I kept a checkbox out side group of checkboxes called chkSolicitation and when check this all group of checkboxes should be unchecked.
If any of the group of checkboxes checked then automatically
chkSolicitation
should be
unchecked.
Onload also If
group of checkboxes unchecked
automatically
chkSolicitation
should be
unchecked and Vice versa.
- <fieldset>
- <!-- these will be affected by check all -->
- <div><input type="checkbox" ID="checkall1"/> Check all</div>
- <div><input type="checkbox"/> Checkbox</div>
- <div><input type="checkbox"/> Checkbox</div>
- <div><input type="checkbox"/> Checkbox</div>
- </fieldset>
- <fieldset>
- <!-- these won't be affected by check all; different field set -->
- <div><input type="checkbox" ID="checkall2"/> Check all</div>
- <div><input type="checkbox"/> Checkbox</div>
- <div><input type="checkbox"/> Checkbox</div>
- <div><input type="checkbox"/> Checkbox</div>
- </fieldset>
- <br/>
- <div><input type="checkbox" ID="chkSolicitation"/> Please do not send me any email</div>
Javascript
- $('[id^=checkall]').click(function(){
- $(this).closest('fieldset').find('input').not(this).prop('checked',this.checked);
- });
- $(':checkbox').not('[id^=checkall]').click(function(){
- var all = $(this).closest('fieldset').find('[id^=checkall]');
- var chks = $(this).closest('fieldset').find('input').not(all);
-
- all.prop('checked', chks.length == chks.filter(':checked').length);
- })