?
Solved

radiobuttonlist find selected index

Posted on 2013-01-11
2
Medium Priority
?
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

765 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