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

getElementsByName()

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'?
I want to do something like:

var name = 'label'+i
text = document.getElementsByName(name).value

Thanks
A
Mar 13 '06 #1
1 9715
On 13/03/2006 13:13, acord wrote:
I want to use document.getElementsByName('name').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.xxxform.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 getElementsByName 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.xxxform.name.value, but allow me pass in a variable name of
the 'name'?


document.forms.xxxform.elements[myName].value

where myName is such a variable.

[snip]

I suggest you read about bracket notation[1].

Mike
[1] <http://www.jibbering.com/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
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
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
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...
4
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 =...
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...
14
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"...
7
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
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...
0
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...

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.