Skip to content Skip to sidebar Skip to footer

Disable Other Checkboxes When One With Similar Class Is Clicked

I need to disable rest of the checkboxes with the same class as soon as one of them gets checked. $('.Cat .RoleChk').change(function(){ if($(this).is(':checked')){ $('.Cat .Ro

Solution 1:

How about:

$(".RoleChk, .GrpChk").change(function() {
    this.checked ? $("." + this.className).not(this).prop("disabled", true) : $("." + this.className).not(this).prop("disabled", false);
});

Demo: http://jsfiddle.net/tymeJV/96Wvq/1/

I kept the original checkbox that was checked enabled, this allows the user to uncheck and re-enable. If you want to remove this functionality, take the .not(this) out of the ternary.

Solution 2:

<script>jQuery(document).ready(function(){
    $('.Cat .RoleChk').change(function(){
        if($(this).is(':checked')){
            $('.Cat .RoleChk').attr('disabled',true);
            $(this).removeAttr("disabled");
        }
        else{
            $('.Cat .RoleChk').removeAttr("disabled");
        }
    });
});
</script>

Post a Comment for "Disable Other Checkboxes When One With Similar Class Is Clicked"