views:

81

answers:

1

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&nbsp;<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") );  
});
+10  A: 
rahul
Remember to leave the name attribute so that the values is posted. (I am not complete sure, that this is necessary, but it's certainly a practice to always specify the name of an input type="checkbox".)
Jan Aagaard
Still there is problem when i try to uncheck the All checkbox. its not working properly
Yashwant Chavan
My actual requirement is 1] When i check All it will check all check boxes.2] When i uncheck All it will uncheck all check boxes.3] When All is checked and uncheck any other it will uncheck All check box.
Yashwant Chavan
In Demo when i try to check below check box it should check All alsoBuyer/ImporterService ProviderSupplier
Yashwant Chavan
ya it working in Another demoThanks
Yashwant Chavan
hi please check my latest updated question
Yashwant Chavan