views:

49

answers:

2
+1  Q: 

Jquery in Checkbox

I have multiple html checkboxes that all have different names.

What I have to do is when it is checked it should disable some radio button that has a different name.

I know it can be simply done using jquery.

Any help...with a simple example..thanks

+2  A: 

.....

 $("input[type=checkbox]").click(function(){
   if($(this).is(":checked")) {
     $("input[type=radio]").attr('disabled', 'disabled');
   }
   else
   {
     $("input[type=radio]").removeAttr('disabled');
   }
 });
Sarfraz
When it's unchecked I would *assume* it should re-enable the radio, though the OP hasn't been perfectly clear on this.
karim79
@karim79: agreed and fixed, forgot that, yes he is not much clear, i have posted rather impractical solution because he has now shown names :(
Sarfraz
+4  A: 
$("input[name=theName]:checkbox").click(function() {
    if($(this).is(":checked")) {
        $("input[name=radioName]:radio").attr("disabled", "disabled");
    } else {
        $("input[name=radioName]:radio").removeAttr("disabled");
    }
});

Shorter way:

$("input[name=theName]:checkbox").click(function() {
    $("input[name=radioName]:radio").attr("disabled", $(this).is(":checked"));
});
karim79