473,602 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alternative to the getElementsByNa me() method

Frinavale
9,735 Recognized Expert Moderator Expert
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.getEle mentByID method) I tried using the document.getEle mentsByName() method when I discover that the element doesn't have a type.

The problem is that the getElementsByNa me 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 4980
Dormilich
8,658 Recognized Expert Moderator Expert
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 Recognized Expert Moderator Expert
I don't know what changed but after much fiddling with this the getElementsByNa me 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
16928
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 = document.getElementsByName("trBook"); v.style.display = 'none';
5
3682
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
12692
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 there something wrong with the program, or is there another way to get elements that have been created dynamically? Thanks. <html> <body>
21
11370
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
9727
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. I thought this 2 functions are identical? If getElementsByName is not the same as the later function, is there any other function I can use which is same as document.xxxform.name.value, but allow me pass in a variable name of the 'name'?
2
5674
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 pages = document.getElementsByName("name");
22
7944
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 am using getElelementsByName since these are radio buttons, but it seems that the dynamic element is not seen!!! This is my code... please let me know if there is anything that I am doing wrong! - thanks ---- ....
4
7965
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 chgMusicLink(userid,userlink,usertype) { var card_music_id = document.getElementsByName(userid).value; document.getElementsByName(userlink).href="/card_music_preview.tcl?card_music_id="+card_music_id+"&card_music_type="+usertype; }
2
2681
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 IE ....if someone can test this code on older IE ? ( and in the hope that it can be usefull for others ! ) 1- It first create a combobox dynamically and set the NAME attribute to it.
0
7993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
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...
1
8054
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,...
1
5867
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
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
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
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
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.