Home > Software engineering >  RadioButtonList is disable using jquery
RadioButtonList is disable using jquery

Time:11-05

I didn't figure out why the below code work on the textbox( id is txt1) and doesn't work on radiobuttonlist (id is rdl). Would someone told me how to do it. Thanks in advance.

There is jquery:

var chk = $('#chk1');
if (chk.prop('checked')) {
        $('#txt1').prop("disabled", false);
        $('#rdl').prop("disabled", false);
 }
else {
    $('#txt').prop("disabled", true);
    $('#rdl').prop("disabled", true);
}
                 

There is the radio button list on the aspx page

<asp:RadioButtonList ID="rdl" runat="server"/>

CodePudding user response:

After I added input[type=radio], it worked.

$('#rdl input[type=radio]').prop("disabled", false);

CodePudding user response:

The reason why this happens is: Web Forms by default sets its own HTML id to elements with the help of the ID you provided, if you do not specify it to be the same you wrote. (Check out the webpage source code when rendered)

<asp:RadioButtonList ID="rdl" ClientID="static" runat="server"/>

Actually, the rdl that you have, is only usable at code behind, if not set static. Also, another solution is you could query through DOM elements with JQuery's "Contain Selector"

$('[id*="rdl"]').prop("disabled", false);
  • Related