select one checkbox from multiple MAIN Checkboxes,disable all other MAIN boxes,n enable child checkbox

Posted by harshil on Stack Overflow See other posts from Stack Overflow or by harshil
Published on 2011-01-05T19:36:05Z Indexed on 2011/01/05 19:53 UTC
Read the original article Hit count: 400

Filed under:
<input type="checkbox" id="chkMain" />
<input type="checkbox" id="chkMain1" />
<input type="checkbox" id="chkMain2" />
<input class="child" type="checkbox" id="chk1" disabled="true" />
<input class="child" type="checkbox" id="chk2" disabled="true" />
<input class="child" type="checkbox" id="chk3" disabled="true" />
<input class="child" type="checkbox" id="chk4" disabled="true" />
<input class="child" type="checkbox" id="chk5" disabled="true" />
<input class="child" type="checkbox" id="chk6" disabled="true" />
<input class="child" type="checkbox" id="chk7" disabled="true" />


$(function(){  
        $("input[id^=chkMain]").click ( function() {  
            if( !$(this).is ( ":checked" ) ){       
                $(".child").attr ( "disabled" , true );

            }      
            else{       
                $(".child").removeAttr ( "disabled" );     
            }   
        }); 
    });

this enables all the child boxes when either chkMain or chkMain1 or chkMain2 are checked. what i want is: when chkMain is checked the code should disable chkMain1 and chkMain2 but enabling child boxes. or when chkMain1 is checked the code should disable chkMain and chkMain2 but enabling child boxes.

© Stack Overflow or respective owner

Related posts about jQuery