Get Selected RadioButtonList Value using JavaScript in ASP.Net
At times, there will be need to get the selected or checked RadioButtonList value from javascript to do some validations on client side.
The following javascript will help us to do that.
<script language="javascript" type="text/javascript">
function GetRDBValue()
{
var radio = document.getElementsByName('rdbGender');
for (var i = 0; i < radio.length; i++)
{
if (radio[i].checked)
{
alert(radio[i].value);
}
}
}
</script>
<asp:RadioButtonList ID="rdbGender" runat="server">
<asp:ListItem Text="Male" Value="1"></asp:ListItem>
<asp:ListItem Text="Female" Value="2"></asp:ListItem>
</asp:RadioButtonList>
|