Hi this is my check boxes
<table cellpadding="0" cellspacing="0" border="1" bordercolor="red" width="100%" >
<tr><td width="50%"><input type="checkbox" name="businessTypeGroup" id="chkAll" value="0" >All</TD><TD><input type="checkbox" name="businessTypeGroup" id="chkBuyer" value="1">Buyer/Importer</td></tr>
<tr><td><input type="checkbox" name="businessTypeGroup" id="chkSeller" value="2">Seller/Exporter/Manufacturer</TD><TD><input type="checkbox" name="businessTypeGroup" id="chkService" value="3">Service Provider</td></tr>
<tr><td><input type="checkbox" name="businessTypeGroup" id="chkDistributor" value="4">Distributor</td><td><input type="checkbox" name="businessTypeGroup" id="chkSupplier" value="5">Supplier</TD></tr>
<tr><td colspan="2"><input type="checkbox" name="businessTypeGroup" id="chkTrading" value="6">Trading Company <span id="businessTypeGroupError"></td></tr>
</table>
As per this code one senario is not working
1] try to check other checkboxes not able to check All
$("input:checkbox[name='businessTypeGroup']").click (function(){
$("input:checkbox[name='businessTypeGroup']").click (function(){
var totalCheckboxes = $("input:checkbox[name='businessTypeGroup']").length;
var checkedCheckboxes = $("input:checkbox[name='businessTypeGroup']:checked").length;
if ( totalCheckboxes === checkedCheckboxes ){
$("#chkAll").attr("checked" , true );
}else{
$("#chkAll").attr("checked" , false );
}
});
});
$("#chkAll").click ( function(){
$("input:checkbox[name='businessTypeGroup']").attr ( "checked" , $(this).attr("checked") );
});
Use ids for the checkboxes and then use the above method since
#is an id selector.or you can use
See attributeEquals selector
Edited
Working Demo
Another demo
This will check the checkbox All when all other checkboxes are checked. And if any one is unchecked then checkbox All will be unchecked.