Link to home
Start Free TrialLog in
Avatar of johnkainn
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:ListItem>
            <asp:ListItem Text="Three"></asp:ListItem>
    </asp:RadioButtonList>
            <br />
            <br />
            <asp:Button ID="btn1" runat="server" OnClientClick="MyTest()" Text="Test" />
    </div>
    </form>
</body>
</html>
Avatar of Big Monty
Big Monty
Flag of United States of America image

function getCheckedRadio() {
      var radioButtons = document.getElementsByName("<%=ListBox1.ClientID%>");
      for (var x = 0; x < radioButtons.length; x ++) {
        if (radioButtons[x].checked) {
          alert("You checked " + radioButtons[x].id);
        }
      }
    }
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial