how to enable textbox when radiobuttonlist is selected yes in asp.net using jquery without using autopostback=true
<asp:RadioButtonList ID="RdoBtnHasNotified" runat="server"
RepeatDirection="Horizontal" AutoPostBack="True"
OnSelectedIndexChanged="RdoBtnHasNotified_SelectedIndexChanged">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0" Selected="True">No</asp:ListItem>
</asp:RadioButtonList></td>
<asp:TextBox ID="TxtHowNotified" runat="server" TextMod开发者_高级运维e="MultiLine" MaxLength="100"></asp:TextBox></td>
This should do the trick:
$('#<%= RdoBtnHasNotified.ClientID =%>').click() {
if ($(this).find('input:checked').val()) == 'Yes' {
$('#idOfYourTextBox').attr('enabled','true');
}
}
<asp:RadioButtonList ID="rbl" runat="server" onclick="Toggle()">
<asp:ListItem Value="0">No</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="TextBox1" runat="server" style="display:none" />
JS
<script type="text/javascript">
function Toggle()
{
var radio = document.getElementsByName('<%=rbl.ClientID %>');
var txt = document.getElementById('<%=TextBox1.ClientID %>');
for (var j = 0; j < radio.length; j++)
{
if (radio[j].checked)
{
if(radio[j].value == '1')
{
txt.style.display = '';
}
else
{
txt.style.display = 'none';
}
}
}
}
</script>
精彩评论