johnkainn
asked on
radiobuttonlist find selected index
Hello,
I would like to find the selected index of Radiobuttonlist. How is best to do that?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function MyTest() {
//Find selected index of ListBox1
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="ListBox1" runat="server">
<asp:ListItem Text="One"></asp:ListItem>
<asp:ListItem Text="Two" Selected="True"></asp:List Item>
<asp:ListItem Text="Three"></asp:ListIte m>
</asp:RadioButtonList>
<br />
<br />
<asp:Button ID="btn1" runat="server" OnClientClick="MyTest()" Text="Test" />
</div>
</form>
</body>
</html>
I would like to find the selected index of Radiobuttonlist. How is best to do that?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function MyTest() {
//Find selected index of ListBox1
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="ListBox1" runat="server">
<asp:ListItem Text="One"></asp:ListItem>
<asp:ListItem Text="Two" Selected="True"></asp:List
<asp:ListItem Text="Three"></asp:ListIte
</asp:RadioButtonList>
<br />
<br />
<asp:Button ID="btn1" runat="server" OnClientClick="MyTest()" Text="Test" />
</div>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var radioButtons = document.getElementsByName
for (var x = 0; x < radioButtons.length; x ++) {
if (radioButtons[x].checked) {
alert("You checked " + radioButtons[x].id);
}
}
}