Solved

asp.net radiobuttonlist selectedindex in javascript

Posted on 2006-06-21
5
5,206 Views
Last Modified: 2012-06-27
Hello

I need to get the selectedindex of a asp.net radiobuttonlist in a javascript, anyone know how to do this?

The radiobuttonlist is declared like this:
------------------------------------------------------------------
<asp:radiobuttonlist id="rbl_menu_atgard" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rbl_menu_atgard_OnChange">
<asp:ListItem Value="Scenario">Scenario</asp:ListItem>
<asp:ListItem Value="Prognos">Prognos</asp:ListItem>
<asp:ListItem Value="Regleringar">Rapportera regleringar</asp:ListItem>
</asp:radiobuttonlist>

The generated html becomes like this:
-------------------------------------------------------------------
<table id="rbl_menu_atgard" border="0">
<tr>
<td><input id="rbl_menu_atgard_0" type="radio" name="rbl_menu_atgard" value="Scenario" onclick="__doPostBack('rbl_menu_atgard_0','')" language="javascript" /><label for="rbl_menu_atgard_0">Scenario</label></td>
</tr>
<tr>
<td><input id="rbl_menu_atgard_1" type="radio" name="rbl_menu_atgard" value="Prognos" onclick="__doPostBack('rbl_menu_atgard_1','')" language="javascript" /><label for="rbl_menu_atgard_1">Prognos</label>
</td>
</tr>
<tr>
<td><input id="rbl_menu_atgard_2" type="radio" name="rbl_menu_atgard" value="Regleringar" checked="checked" onclick="__doPostBack('rbl_menu_atgard_2','')" language="javascript" /><label for="rbl_menu_atgard_2">Rapportera regleringar</label>
</td>
</tr>
</table>



when i retrieve the radiobuttonlist in a javascript like this:
var menu = document.getElementById('rbl_menu_atgard');

i can't access the selectedindex and options array. I need help on how to solve this.

please

/Nick
0
Comment
Question by:nicas
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
Nandakumar Sakthivel earned 250 total points
ID: 16950764
hi,
   you can use some thing like this

                      var val = 0;
                  for( i = 0; i < document.Form1.RadioButtonList1.length; i++ )
                  {
                        if(document.Form1.RadioButtonList1[i].checked == true )
                                    val = document.Form1.RadioButtonList1[i].value;
                  }
 
 RadioButtonList1 is name of the radio button group

Thanks,
Nanda
0
 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 17135940
Volunteer,
              I think that what i had answered is relevant to the question and i think that my solution will solve the posted problem.

Thanks,
Nanda
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

830 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