How to enable / disable a txt from a choice of a jquery radiobutton?

1

I need to enable / disable a field according to the choice in a radiobutton

Validations

This field should only be active when the "Inactive" radio button is selected Here is the code:

RadioButton:

<asp:Label ID="Label40" runat="server" Width="85px" Style="margin-top: 15px; margin-left: 17.2%;">DADOS</asp:Label>
                            <div style="border: solid 2px; height: 22px; width: 316px; margin-left: 50.4%; margin-top: -33px;">
   <asp:RadioButtonList ID="rdbDados" name="rdbDados" CssClass="radioItens2" runat="server" RepeatDirection="Horizontal" Style="width: 319px;">
  <asp:ListItem Text="1º PEDIDO" Value="C" Selected="True"></asp:ListItem>
     <asp:ListItem Text="INATIVOS" Value="I"></asp:ListItem>
    </asp:RadioButtonList>
 </div>

Field that needs to be enabled / disabled

 <asp:Label runat="server" Width="90">Nº MESES INATIVIDADE</asp:Label>
 <asp:TextBox runat="server" Width="50px" ID="txtInatividade" name="inatividade"></asp:TextBox>

Jquery that I tried to develop:

$("#<%=rdbDados.ClientID%>").change(function () {
           switch ($("#rdbDados input:radio:checked").val()) {
        case "I":
            $("#inatividade").prop("disabled", false);
            break;
        case "C":
            $("#inatividade").prop("disabled", true);
            break;
    }
});
    
asked by anonymous 09.01.2018 / 14:41

1 answer

1
$("#<%=rdbDados.ClientID%>").change(function () {
    $("#inatividade").prop("disabled", $("#rdbDados input:radio").is(':checked'));
});
    
12.01.2018 / 14:27