473,385 Members | 1,927 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,385 software developers and data experts.

Alternative to the getElementsByName() method

Frinavale
9,735 Expert Mod 8TB
I'm attempting to intercept the click event for RadioButons in an attempt to ask the user for confirmation of their action.

I determined that Internet Explorer does not reset the previous selection if the user was to cancel the action.

In order to reset the previous select (cancel the new selection) I have to save a reference to the original selected radio button....well actually right now I'm just attempting to save the ID of the original radio button.

Anyways, my problem isn't entirely related to this.

My problem is that I'm trying to intercept the click event for an ASP.NET RadioButtonList control.

My server code provides the client ID of the RadioButtonList control so that my JavaScript control can apply itself to the associated controls.

Apparently the ASP.NET RadioButtonList renders as an HTML Table element with rows of radio buttons:
Expand|Select|Wrap|Line Numbers
  1. <table id="RadioButtonList1" border="0">
  2.     <tr>
  3.         <td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_0">1</label></td>
  4.     </tr><tr>
  5.         <td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" checked="checked" /><label for="RadioButtonList1_1">2</label></td>
  6.     </tr><tr>
  7.         <td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="3" /><label for="RadioButtonList1_2">3</label></td>
  8.     </tr>
  9. </table>
  10.  
So instead of using the $get() method (the document.getElementByID method) I tried using the document.getElementsByName() method when I discover that the element doesn't have a type.

The problem is that the getElementsByName method is only returning the Table and not the RadioButtons.

Is there something else that I can use to retrieve the RadioButtons so that I don't have to loop through the table cells?
May 14 '09 #1
2 4955
Dormilich
8,658 Expert Mod 8TB
you could try
Expand|Select|Wrap|Line Numbers
  1. var tbl = … // the table
  2. var boxes = tbl.getElementsByTagName("input"); // provided there are only the checkboxes in the table
May 14 '09 #2
Frinavale
9,735 Expert Mod 8TB
I don't know what changed but after much fiddling with this the getElementsByName method decided to start working the way I though it it should (returning me all elements that have the name provided).

I must be tired or something...

Thanks Dormilich
May 14 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: AR | last post by:
Hi, How can I hide table rows? ... tried with the following example: FireFox works... How to do the simillar in IE6? <html> <head> <script language="javascript"> function hide_row() { var v...
5
by: simon | last post by:
<html> <head> <script language="vbscript"> sub window_onload msgbox document.getElementsByName("name1").length end sub </script> </head> <body> <div name="name1">testDiv</div>
6
by: mitch | last post by:
It seems like if you create an element dynamically with createElement() and then try to get it later with getElementsByName() it's found in Firefox but not in IE. Here's an example program. Is...
21
by: briggs | last post by:
<html> <head> <script> /* AddChild */ function ac() { var c; var p = document.getElementById("p"); for (var i = 0; i < 5; i++) { c = document.createElement("DIV"); // Create 'div' element.
1
by: acord | last post by:
Hi, I want to use document.getElementsByName('name').value to retrieve a value of the field 'name', but it returns undefined. But function document.xxxform.name.value returns the correct value....
2
by: André Wagner | last post by:
I'm trying to get all the "divs" that have a given NAME using getElementsByName(). For example, the following code: <html> <head> <script type="text/javascript"> function on_load() { var...
22
by: Saul | last post by:
I have a set of radio buttons that are created dynamically, after rendered I try loop thru this set by getting the length of the set, but I keep getting an error stating the element is undefined. I...
4
by: david.kuczek | last post by:
I got the following error in a javascript I wrote. The script works fine, but why is the error being displayed??? ##### Here comes the little script: function...
2
by: tsalm | last post by:
Hi everybody, I need to get a element create dynamically by its name. It's ok for FF, but on IE, getElementsByName return "undefined". I create this code but not sure that it can work on older...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
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...

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.