Solved

radiobuttonlist find selected index

Posted on 2013-01-11
2
267 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
innerHTML 7 35
Add or delete table rows 10 54
ASP.NET MVC -Update model when click on <li> element 29 35
JS Event Does not Trigger From File 2 28
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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

829 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