Getting selected value from asp.net RadioButtonList using JavaScript.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 296
Write below code:-

<script language="javascript" type="text/javascript">
function GetSelectedValue()
{
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