Home > Code > Javascript > How to get selected value from asp.net RadioButtonList using JavaScript?

How to get selected value from asp.net RadioButtonList using JavaScript?

by Thamil   on Sep 10, 2013   Category: Javascript   |  Views: 18295    |  Points: 25   |  Gold 


Below code snippet will help you how to get selected values from RadioButtonList using JavaScript in a simple way

<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.checked) {
Checkdvalue = rdbtnLstValues;
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>




Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts