1

I have an application page in which two radio buttons and a people editor control is there.

My requirement is, if radio button "Yes" is checked then the people editor control should be enabled other wise it should be disabled.

My JavaScript code is:

<script type="text/javascript">
    $(document).ready(function(){   
        var radYes = document.getElementById("<%= rbtnReferralYes.ClientID %>");
        var radNo = document.getElementById("<%= rbtnReferralNo.ClientID %>");
        var peopleEditor = document.getElementById("<%= peReferralUsers.ClientID %>");
        $(peopleEditor).prop('disabled',true);
        $(radYes).click(function() {                    
            $(peopleEditor).prop('disabled',false);
        });
        $(radNo).click(function() {                 
            $(peopleEditor).prop('disabled',true);
        });
    });
</script>

My problem is that this code is working fine in IE but not working in Chrome and Firefox.

What am I missing?

1 Answer 1

1

You can it with .attr() like this:

$(peopleEditor).attr("disabled", 'disabled');

Or you can try to hide and show with .hide() and .show() but then its completely not visible.

EDIT: You have to check if your radiobutton is checked:

    $(peopleEditor).prop('disabled',true);
    $(radYes).click(function() {                    
       if($(radYes).is(':checked')) { 
          $(peopleEditor).prop('disabled',false);
       } 
    });
    $(radNo).click(function() {
       if($(radNo).is(':checked')) { {                 
          $(peopleEditor).prop('disabled',true);
       }
    });

Radiobuttons with jQuery

Or you can use only one Checkbox for enabeling/disabling the peopleEditor field

8
  • thanks for answering sir, I tried this way but not working. :-(
    – users1100
    Mar 6, 2014 at 6:58
  • any errors for ff and chrome?
    – mbauer
    Mar 6, 2014 at 7:06
  • No sir, I am not getting any error. I debugged the JavaScript in Firebug(in firefox). and found that the break point does not get executed placed over $(radYes).click(function() {$(peopleEditor).prop('disabled',false);});
    – users1100
    Mar 6, 2014 at 7:14
  • you may have to check if the button is checked, see my edited answer
    – mbauer
    Mar 6, 2014 at 7:20
  • I tried the edited code also, but not working sir.
    – users1100
    Mar 6, 2014 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.