473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get RadioButtonList's selected value in js

mg

After a selection is made in the following RadioButtonList

<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Value="Y"></asp:ListItem>
<asp:ListItem Value="N"></asp:ListItem>
</asp:RadioButtonList>
the following script [in a client-side CustomValidator]
returns null, not "Y" or "N"

<script language="javascript">
q = document.getElementById
("RadioButtonList1").getAttribute("SelectedValu e")
alert(q)
</script>

Can you tell me what I'm doing wrong?
Nov 18 '05 #1
2 19996
As far as I know, you can't get the selected value of a radio button
directly. You need to iterate through each item in the group, until you
find the selected item, and then get its value. An example of how to do
this is below:

<script language="javascript">
function GetVal()
{
var a = null;
var f = document.forms[0];
var e = f.elements["RadioButtonList1"];

for (var i=0; i < e.length; i++)
{
if (e[i].checked)
{
a = e[i].value;
break;
}
}
return a;
}
</script>

Hope this helps,

Mun

"mg" <mg@theworld.com> wrote in message
news:03****************************@phx.gbl...

After a selection is made in the following RadioButtonList

<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Value="Y"></asp:ListItem>
<asp:ListItem Value="N"></asp:ListItem>
</asp:RadioButtonList>
the following script [in a client-side CustomValidator]
returns null, not "Y" or "N"

<script language="javascript">
q = document.getElementById
("RadioButtonList1").getAttribute("SelectedValu e")
alert(q)
</script>

Can you tell me what I'm doing wrong?


Nov 18 '05 #2
mg
Thanks!

-----Original Message-----
As far as I know, you can't get the selected value of a radio buttondirectly. You need to iterate through each item in the group, until youfind the selected item, and then get its value. An example of how to dothis is below:

<script language="javascript">
function GetVal()
{
var a = null;
var f = document.forms[0];
var e = f.elements["RadioButtonList1"];

for (var i=0; i < e.length; i++)
{
if (e[i].checked)
{
a = e[i].value;
break;
}
}
return a;
}
</script>

Hope this helps,

Mun

"mg" <mg@theworld.com> wrote in message
news:03****************************@phx.gbl...

After a selection is made in the following RadioButtonList
<asp:RadioButtonList id="RadioButtonList1" runat="server"> <asp:ListItem Value="Y"></asp:ListItem>
<asp:ListItem Value="N"></asp:ListItem>
</asp:RadioButtonList>
the following script [in a client-side CustomValidator]
returns null, not "Y" or "N"

<script language="javascript">
q = document.getElementById
("RadioButtonList1").getAttribute("SelectedValu e")
alert(q)
</script>

Can you tell me what I'm doing wrong?


.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hazzard | last post by:
I store radiobuttonlist values in the db using the string value of the radio button item value. (nvarchar) I am creating an edit functionality on the asp.net form so that when I reuse my...
2
by: Sean | last post by:
Hi .... I have a radiobutton list and a label in a webform. <asp:radiobuttonlist id="one" runat="server" CssClass="text" AutoPostBack="False" RepeatDirection="Horizontal"> <asp:ListItem...
3
by: William LaMartin | last post by:
If I create a RadioButtonList with, say, two items, then after the page loads and I select one of the items and then click on a button whose click event contains some code to display the...
5
by: DotNetGruven | last post by:
Anyone have any pointers on how to set the Value and Selected attributes in a ListItem in a RadioButtonList that is in a DataGrid? Here's what I have ------DataGrid------ -- BoundColumn 0 --...
0
by: Jay | last post by:
I have a radiobuttonlist like so <asp:RadioButtonList id=radType RepeatDirection="Horizontal" cellpadding="10" cellspacing="0" runat="server"><asp:ListItem value="Something1"><font...
4
by: Emil | last post by:
Can somebody tell me what would be the syntax for having an if statement and setting the selected index of a radiobuttonlist? This is my first project using ASP.net and I use C#. I have a repeater...
0
by: Luis Esteban Valencia | last post by:
http://www.codeproject.com/aspnet/DataGridCCEvents.asp#xx1009236xx Read this first and see if you can help me have tried but the Intelisense of the radiobuttonlist doestn have the event...
4
by: juststarter | last post by:
Hello, I have an aspx file where i've put a placeholder element. On load (page_load) i create dynamically an html table which contains a checkbox and a radiobuttonlist in each tablerow . The...
2
by: Michael Bohman | last post by:
Hi, i have a small problem with assigning a database value to a RadioButtonList control. On my form i have 3 user admin=1, premium=2 and basic=3, theese values is stored in an access database in a...
6
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.