Show hide TextBox on RadioButtonList selection using jQuery in ASP.Net

Last Reply 6 months ago By pandeyism

Posted 6 months ago

hello,

 

i have asp dot net radio button list which has 2 options Yes and No.

i want javascript that if user select Yes so textbox visible and its set the value of textbox to "I am selected" and if user select No textbox hide

 

please advice

Posted 6 months ago

Hi nauna,

Please refer below sample.

HTML

<asp:RadioButtonList ID="rblYesNo" runat="server">
    <asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
    <asp:ListItem Text="No" Value="No"></asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtData" runat="server" />
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$("document").ready(function () {
    $("#<%= rblYesNo.ClientID%> input").change(function () {
        if ($(this).val() == 'No') {
            $('#<%= txtData.ClientID%>').hide();
        }
        else {
            $('#<%= txtData.ClientID%>').show();
            document.getElementById('<%=txtData.ClientID%>').value = "I am selected";
        }
        return false;
    });
});
</script>