Solved

radiobuttonlist find selected index

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

Expert Comment

by:Big Monty
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now