473,585 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementsByNa me()

Hi,

I want to use document.getEle mentsByName('na me').value to retrieve a
value of the field 'name', but it returns undefined.
But function document.xxxfor m.name.value returns the correct value.

I thought this 2 functions are identical? If getElementsByNa me is not
the same as the later function, is there any other function I can use
which is same as document.xxxfor m.name.value, but allow me pass in a
variable name of the 'name'?
I want to do something like:

var name = 'label'+i
text = document.getEle mentsByName(nam e).value

Thanks
A
Mar 13 '06 #1
1 9726
On 13/03/2006 13:13, acord wrote:
I want to use document.getEle mentsByName('na me').value to retrieve a
value of the field 'name', but it returns undefined.
Why? Using the forms and elements collections is likely to work across a
wider range of user agents.
But function document.xxxfor m.name.value returns the correct value.
Notice the plural, '...Elements... '? DOM methods and properties that use
a singular form (such as getElementById) return a single value. Those
that use a plural in their name return a collection (similar to an array).
I thought this 2 functions are identical?
The latter is not a function. It is a series of property accessors.
If getElementsByNa me is not the same as the later function
It is not. For a start, it returns a collection of elements from across
the entire document, not just a particular form.
is there any other function I can use which is same as
document.xxxfor m.name.value, but allow me pass in a variable name of
the 'name'?


document.forms. xxxform.element s[myName].value

where myName is such a variable.

[snip]

I suggest you read about bracket notation[1].

Mike
[1] <http://www.jibbering.c om/faq/#FAQ4_39>

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Mar 13 '06 #2

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

Similar topics

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>
21
11367
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.
2
5670
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
7943
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...
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; ...
4
21558
by: Otto Wyss | last post by:
I've tried to access the value of a selected option through the following getSelectValue function, passing the name of the select function getSelectValue (name) { var sel = document.getElementsByName(name); var i = sel.options.selectedIndex; return i == -1? "": sel.options.value; } getSelectValue ('belongsto')
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...
14
8139
rrocket
by: rrocket | last post by:
I am passing a value through query string to a popup and then trying to pass it back to the main page... I store the value in a hidden input box <input type="text" name="FromZip" id="FromZip" value="<% response.write(Request.QueryString("txtZipFr")) %>" /> and am passing it back through query string to the main page with <script...
7
374
by: lukaszmn | last post by:
Hi, I cannot figure out why everything from line "var elem = doc.getElementsByName('keywords')" in x.js is not executed. I want to set value of <input name=keywords ...which is in a.html after page is loaded. ------------------ search.html -------------------- <html> <head> <title>Search</title>
0
7908
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...
0
7836
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
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. ...
1
7950
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...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
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...
0
3835
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...
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1175
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...

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.