Getting selected value from RadioButtonList using JavaScript.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 222
Below code snippet will help us how to get selected values from RadioButtonList using JavaScript in a simple way:-

<script language = "javascript" type = "text/javascript">
function Get_RadiobuttonList_SelectedValue()
{
var list = document.getElementById("<%= rdbtnLst.ClientID %>"); //Cleint ID of RadioButtonList
var rdbtnLstValues = list.getElementsByTagName("input");
var Checkdvalue;
for (var i = 0; i < rdbtnLstValues.length; i++)
{
if (rdbtnLstValues[i].checked)
{
Checkdvalue = rdbtnLstValues[i];
break;
}
}
if (Checkdvalue)
{
alert(Checkdvalue.value);
}
}
</script>
<div>
<asp:RadioButtonList ID="rdbtnLst" AutoPostBack="true" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True">One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
<asp:ListItem>Four</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="Button1" runat="server" OnClientClick="GetSelectedValue()" Text="Button" />
</div>

Comments or Responses

Login to post response