Skip to content Skip to sidebar Skip to footer

How To Uncheck Checkbox When Radio Button Is Checked And Uncheck Radio Button When Checkboxes Are Checked Using Javascript

Male Female

Solution 1:

I hope this is what you were looking for:

HTML:

<divid="a"><inputtype="radio"name="sex"value="male">Male<br><inputtype="radio"name="sex"value="female">Female
</div><divid="b"><inputtype="checkbox"name="vehicle"value="Bike">I have a bike<br><inputtype="checkbox"name="vehicle"value="Car">I have a car 
</div>

JS:

$('input[type="radio"]').change(function() {
    if ($(this).is(':checked')){ //radio is now checked
        $('input[type="checkbox"]').prop('checked', false); //unchecks all checkboxes
    }
});

$('input[type="checkbox"]').change(function() {
    if ($(this).is(':checked')){
        $('input[type="radio"]').prop('checked', false);
    }
});

Fiddle:

http://jsfiddle.net/24kg2/

Post a Comment for "How To Uncheck Checkbox When Radio Button Is Checked And Uncheck Radio Button When Checkboxes Are Checked Using Javascript"