473,793 Members | 2,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get RadioButtonList 's selected value in js

mg

After a selection is made in the following RadioButtonList

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

<script language="javas cript">
q = document.getEle mentById
("RadioButtonLi st1").getAttrib ute("SelectedVa lue")
alert(q)
</script>

Can you tell me what I'm doing wrong?
Nov 18 '05 #1
2 20017
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="javas cript">
function GetVal()
{
var a = null;
var f = document.forms[0];
var e = f.elements["RadioButtonLis t1"];

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.co m> wrote in message
news:03******** *************** *****@phx.gbl.. .

After a selection is made in the following RadioButtonList

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

<script language="javas cript">
q = document.getEle mentById
("RadioButtonLi st1").getAttrib ute("SelectedVa lue")
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="javas cript">
function GetVal()
{
var a = null;
var f = document.forms[0];
var e = f.elements["RadioButtonLis t1"];

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.co m> wrote in message
news:03******* *************** ******@phx.gbl. ..

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

<script language="javas cript">
q = document.getEle mentById
("RadioButtonLi st1").getAttrib ute("SelectedVa lue")
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
5672
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 dataentry form for edit, I search the database for the row containing the data I want, and then populate all the form fields. here is what I have so far. What I don't know what to do is for cases where a dirty database has no associated value for the...
2
8085
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 Value="one">one</asp:ListItem> <asp:ListItem Value="two">two</asp:ListItem> <asp:ListItem Value="three">three</asp:ListItem> <asp:ListItem Value="four">four</asp:ListItem>
3
9010
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 RadioButtonlList's selected value, there is nothing. On a postback, with the dynamically created button list visible on the page and the first item selected, if I try some code like "If Me.RadioButtonList1.Items(0).Selected = True Then.......", then I...
5
5511
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 -- -- BoundColumn 1 -- -- BoundColumn 2 -- -- TemplateColumn 4 -- -- RadioButtonList --
0
1018
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 face="arial,helvetica" size="2">Something 1</font></asp:ListItem><asp:ListItem value="Something2"><font face="arial,helvetica" size="2">Something 2</font></asp:ListItem><asp:ListItem value="Something3"><font face="arial,helvetica" size="2">Something...
4
9668
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 with like a table layout and in the last column I want to have three radio buttons (for each row in repeater). The value of the radio button should be calculated from a value from the dataset. How can I do that? When I try to use a variable...
0
1977
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 selectedindexchanged? I have a datagrrid with an itemtemplate, inside this itemtemplate thre is a radiobuttonlist with 3 options. There is also a label to the side of this radiobuttonlist.
4
4009
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 radiobuttonlist contains two items (yes,no). Both the checkboxes and the radiobuttonlist are NOT autopostbacked ( .autopostback = false). When i press the submit button a sub (submit_pressed) is run. My problem is that i can not get the selected items...
2
4739
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 text string. My problem is that when i'm loading my form, it uses a repeater control for each user by the way, I can't find a way to assign either of these values to the RadioButtonList Control. I can read them from the database but i wan't the...
6
2643
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 in the page and I've got code to get the selected value from it in the Radiobuttonlist_SelectedIndexChanged event. The code in there is: Protected Sub rblFMSValue_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
0
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.