Monday, 26 August 2013

Jquery - How can I check if all of the checkboxes are checked?

Jquery - How can I check if all of the checkboxes are checked?

pFor some reason my code doesn't work?! I need to check checkboxes, if all
are unchecked, then enable hidden field and send value to db, so I can
identify that checkboxes were unchecked./p pstrongQuestion 1:/strong Why
isn't my jquery code working?/p pstrongQuestion 2:/strong I need to record
checked or unchecked values to DB. My plan is to check if none selected in
php. Is this a good practice?/p pstrongHTML/strong/p precodelt;tr
class=more_infogt; lt;th valign=topgt;Other options:lt;/thgt; {foreach
from=$HTML_cOPTIONS key=dbname item=optname} {if !
empty($CARINFO[car].{$dbname})} lt;tdgt;lt;input type=checkbox
id=forced_checkbox name=c_options[] value={$dbname} checked/gt; {$optname}
lt;/brgt;lt;/tdgt; {else} lt;tdgt;lt;input type=checkbox
id=forced_checkbox name=c_options[] value={$dbname}/gt; {$optname}
lt;/brgt;lt;/tdgt; {/if} {/foreach} lt;input type=hidden
id=forceSendCheckBox name=c_options[] value=nocheckboxes/gt; lt;/trgt;
/code/pre pstrongJquery/strong/p
precode$('#check').bind('click',function() { if
($('#forced_checkbox').filter(':not(:checked)').length == 0) {
console.log('at least one checked');
$(#forceSendCheckBox).prop('disabled',true);//do not send this field to DB
} else { console.log('nothing checked');
$(#forceSendCheckBox).prop('disabled',false);//send empty checkboxes } });
/code/pre

No comments:

Post a Comment