Solved

radiobuttonlist find selected index

Posted on 2013-01-11
2
266 Views
Last Modified: 2013-01-11
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>
0
Comment
Question by:johnkainn
2 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 38768535
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);
        }
      }
    }
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38768541
Test page : http://jsfiddle.net/LpruQ/1/
        function MyTest() {
            var ListBox1 = document.getElementById("ListBox1")
            var ListItems = ListBox1.getElementsByTagName("input");
            for (var i = 0; i < ListItems.length; i++) if (ListItems[i].checked) break;
            alert(ListItems[i].value);
            return false;
        }

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question