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

getElementByName

is it document.getElementByName or document.getElementsByName?
^

reason I ask is that I have to change ref's in my code from document.all
to sthg that works also in FF... so changed something like this

docslide = document.all['slide'];
docslide = document.getElementByName("slide");

but then looked in Danny G's DOM ref
(http://www.dannyg.com/dl/JSB5RefBooklet.pdf)

and there's a "s" after "Element"

if I search in google for document.getElementsByName with or w/o that
"s" I find entries for both.. pls, which one is it? b/c neither one is
working for me.. thanks..

Frances

Jan 9 '06 #1
20 331048
On 09/01/2006 15:39, Frances wrote:
is it document.getElementByName or document.getElementsByName?
The latter. The method returns a collection so its name uses a plural form.

[snip]
but then looked in Danny G's DOM ref
Based on the testament of other regulars in this group, Danny Goodman is
not a trusted source of scripting information. I've only read one
article written by him (an e-mail), and its content would have me draw
the same conclusion.

[snip]
[N]either one is working for me.. thanks..


Link?

Mike

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


Frances wrote:
is it document.getElementByName or document.getElementsByName?
The specification is here
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-71555259>
the specified method name is getElementsByName.
reason I ask is that I have to change ref's in my code from document.all
to sthg that works also in FF... so changed something like this

docslide = document.all['slide'];


If you have e.g.
<div id="slide">
with a unique id then you might be better off to use
document.getElementById('slide')

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 9 '06 #3
Frances wrote:
is it document.getElementByName or document.getElementsByName?
The latter one, where the name is because the method returns a collection
of element object references, not one element object reference.
^ reason I ask is that I have to change ref's in my code from document.all
to sthg that works also in FF... so changed something like this

docslide = document.all['slide'];
docslide = document.getElementByName("slide");
Use IDs and document.getElementById(...) instead. Unless you do not want
to support IE 4 users anymore, you should not replace document.all[...] with
the latter but implement it as an alternative if the feature-test for the
latter failed.

<URL:http://pointedears.de/scripts/test/whatami>
<URL:http://jibbering.com/faq/#FAQ4_26>
but then looked in Danny G's DOM ref
(http://www.dannyg.com/dl/JSB5RefBooklet.pdf)
That is not a good book, as there are few good books about the subjects
discussed here out there, if any.

<URL:http://jibbering.com/faq/#FAQ3_1>

As for me, Flanagan's book is old enough and revealed too many errors
here, that I cannot recommend it either.
and there's a "s" after "Element"

if I search in google for document.getElementsByName with or w/o that
"s" I find entries for both.
Yes, there are many incompetent people out there which is why the number
of Google hits does not qualify as proof for existence of a name.
pls, which one is it? b/c
"w/o" == "without"?
"b/c" == "because"?

Do not assume that other people understand these abbreviations.
neither one is working for me.. [...]


<URL:http://jibbering.com/faq/#FAQ4_43>
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-71555259>
<URL:http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-getElBId>
PointedEars
Jan 9 '06 #4

Frances wrote:
is it document.getElementByName or document.getElementsByName?
As mentioned by many others, it is document.getElementsByName.
docslide = document.getElementByName("slide");


It doesn't work as you expected because this method looks for HTML
elements with the name 'slide', not elements with an attribute value of
'slide'. Thus, you should use a different method, for example:

docslide = document.getElementById("slide");

where you have:

<div id = "slide">...</div>

Jan 9 '06 #5
VK

Frances wrote:
is it document.getElementByName or document.getElementsByName?


That was well explained to others but there is always something to add
:-)

getElementsByName in IE (Internet Explorer) grabs all elements *with
such id or with such name* - it doesn't give a damn of difference. It
is not standard but fair spelled in the method description on MSDN.

Also it is W3C (and common sense) requirement that id's and names must
be unique for each element on one page. So the presence of
getElementsByName method by itself is a mistery. I think that someone
in W3C was just starting to learn HTML while writing the relevant
standards for it (it happens).

Do not confuse it with getElementsByTagName - here "elements" are
plural because on the same page can be any amount of <p>, <div> and so
elements..

Jan 9 '06 #6
On 09/01/2006 20:02, VK wrote:

[snip]
Also it is W3C (and common sense) requirement that id's and names must
be unique for each element on one page.


An id attribute value must be unique within a document, however, this is
not true for all name attributes.

The name attributes that are, on the whole, backwards-compatible
identifiers (A, APPLET, FORM, FRAME, IFRAME, IMG, MAP) should be unique.
Form controls (BUTTON, INPUT, OBJECT, SELECT, TEXTAREA) can, and in some
cases (radio buttons and checkboxes) must, be duplicates. The remaining
elements (META, PARAM) are not so well-defined as their use tends to
fall outside the scope of HTML.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 9 '06 #7
VK wrote:
Frances wrote:
is it document.getElementByName or document.getElementsByName?

That was well explained to others but there is always something to add
:-)

getElementsByName in IE (Internet Explorer) grabs all elements *with
such id or with such name* - it doesn't give a damn of difference. It
is not standard but fair spelled in the method description on MSDN.

Also it is W3C (and common sense) requirement that id's and names must
be unique for each element on one page.


That is a requirement of IDs but not for all elements that can have a name
- e.g. radio buttons.
[...]
I think ...


.... you didn't check the specification:

<URL:http://www.w3.org/TR/html4/index/attributes.html>
[...]

--
Rob
Jan 9 '06 #8
Michael Winter wrote:
On 09/01/2006 20:02, VK wrote:
Also it is W3C (and common sense) requirement that id's and names must
be unique for each element on one page.
An id attribute value must be unique within a document, however, this is
not true for all name attributes.


True.
The name attributes that are, on the whole, backwards-compatible
identifiers (A, APPLET, FORM, FRAME, IFRAME, IMG, MAP) should be unique.


How did you get that idea?
PointedEars
Jan 9 '06 #9
CK
Definitely getElementsByName... It returns an array of elements with that
name attribute. Then you can access individual values by looping through
the array.

aFields = document.getElementsByName('test');
for (x = 0; aFields.length; x++)
{ alert(aFields[x].value); }

hope this helps.

Chris

"Frances" <fd***@yahoo.com> wrote in message
news:43**********@x-privat.org...
is it document.getElementByName or document.getElementsByName?
^

reason I ask is that I have to change ref's in my code from document.all
to sthg that works also in FF... so changed something like this

docslide = document.all['slide'];
docslide = document.getElementByName("slide");

but then looked in Danny G's DOM ref
(http://www.dannyg.com/dl/JSB5RefBooklet.pdf)

and there's a "s" after "Element"

if I search in google for document.getElementsByName with or w/o that "s"
I find entries for both.. pls, which one is it? b/c neither one is
working for me.. thanks..

Frances

Jan 9 '06 #10
On 09/01/2006 21:13, Thomas 'PointedEars' Lahn wrote:
Michael Winter wrote:


[snip]
The name attributes that are, on the whole, backwards-compatible
identifiers (A, APPLET, FORM, FRAME, IFRAME, IMG, MAP) should be unique.


How did you get that idea?


I recall a similar discussion last year.

Subject: firefox and innerHTML
Message-ID: <ew******************@text.news.blueyonder.co.uk >
Date: 2005-07-12 16:49:14 GMT

Though browsers can cope with duplicated attribute values, it is my
opinion that the /intent/ was for them to be unique.

As I mention in the cited post, the addition of these name attribute was
a revision to HTML 4.0 (which introduced the id attribute). Netscape,
which first designed and implemented several of the listed elements
before HTML 4.0, and did not support the id attribute, presumably
adopted the name attribute as an identifier due to the precedent set by
links (that is, A elements).

As I also note in that post, the collection nature of DOM 0 does not
extend to FORM elements. In a quick test in Fx 1.5 (because it was
running), it doesn't cover APPLET, A (obviously), IMG, or IFRAME
elements, either (I didn't test FRAME and MAP elements). If duplication
was expected, why would scripting mechanisms not have been written to cope?

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 9 '06 #11
VK

Lee wrote:
Where did you get the idea that names must be unique?
Have you never used checkboxes?


You meant to say "radio button" of course. Yes, radio button *group* is
one, and what's going to be two?
It is nice from W3C to provide a whole separate method for a single
case instance, but should it be added then to form or radio object
itself instead?

The only other occasion I may think of (with my humble mind of course)
is that ugly "improvement" of PHP where elements named like "name[]"
will be automatically glued together into array on the server side. I
call this ugly because one should never break long time commonly
accepted standards to implement your own freshly invented ones.
Plus it gives a terrible school to newcomers. If you look at this group
archives like 2-3 years ago it will be full of questions like: how to
access form element named "foo[]" - document.forms[0].foo[] doesn't
work! and similar... Plus a reasonnable question after such "practice"
is: why the hell id's should be any different? - thanks to PHP.
Thinking back document.getElementsByName may be a W3C "endorsment"
towards PHP (? pure speculation).

Jan 9 '06 #12
VK wrote:
You meant to say "radio button" of course. Yes, radio button *group*
is one, and what's going to be two?
It is nice from W3C to provide a whole separate method for a single
case instance, but should it be added then to form or radio object
itself instead?
I often use forms with multiple <input> tags with the same name.
Radio buttons are not a special case, it's just a common example of the
general case.
Multiple inputs with the same name (even of different types!) has been
supported forever.
The only other occasion I may think of (with my humble mind of course)
is that ugly "improvement" of PHP where elements named like "name[]"
will be automatically glued together into array on the server side. I
call this ugly because one should never break long time commonly
accepted standards to implement your own freshly invented ones.
Which standard is broken? None.
Plus it gives a terrible school to newcomers. If you look at this
group archives like 2-3 years ago it will be full of questions like:
how to access form element named "foo[]" - document.forms[0].foo[]
doesn't work! and similar...


Which is why I always recommend accessing form elements with the syntax:

document.forms['formname'].elements['elementname']

This will cause no problems with form fields with '[]' in them.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jan 9 '06 #13
VK said the following on 1/9/2006 5:32 PM:

<snip>
I call this ugly because one should never break long time commonly
accepted standards to implement your own freshly invented ones.


There are terms for breaking long time standards to implement your own:

progress
innovation

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '06 #14
On Mon, 09 Jan 2006 17:22:52 +0100, in comp.lang.javascript , Thomas
'PointedEars' Lahn <Po*********@web.de> in
<20****************@PointedEars.de> wrote:
Frances wrote:

[snip]
if I search in google for document.getElementsByName with or w/o that
"s" I find entries for both.


Yes, there are many incompetent people out there which is why the number
of Google hits does not qualify as proof for existence of a name.


Which makes me wonder what is the verifiably objectively wrong
statement with the largest number of Google hits?
--
Matt Silberstein

Do something today about the Darfur Genocide

http://www.beawitness.org
http://www.darfurgenocide.org
http://www.savedarfur.org

"Darfur: A Genocide We can Stop"
Jan 19 '06 #15
Matt Silberstein wrote on 19 jan 2006 in comp.lang.javascript:
Which makes me wonder what is the verifiably objectively wrong
statement with the largest number of Google hits?


"True"

<http://www.google.com/search?q=true>

777,000,000 hits. [some of which are true, methinks]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 19 '06 #16
Evertjan. said the following on 1/19/2006 11:47 AM:
Matt Silberstein wrote on 19 jan 2006 in comp.lang.javascript:
Which makes me wonder what is the verifiably objectively wrong
statement with the largest number of Google hits?
"True"


"Not" :)
<http://www.google.com/search?q=true>

777,000,000 hits. [some of which are true, methinks]


<URL: http://www.google.com/search?q=not >
10,470,000,000 hits.

<URL: http://www.google.com/search?q=true >
Shows me 1,190,000,000 hits.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 19 '06 #17
Randy Webb wrote on 19 jan 2006 in comp.lang.javascript:
Evertjan. said the following on 1/19/2006 11:47 AM:
Matt Silberstein wrote on 19 jan 2006 in comp.lang.javascript:
Which makes me wonder what is the verifiably objectively wrong
statement with the largest number of Google hits?


"True"


"Not" :)
<http://www.google.com/search?q=true>

777,000,000 hits. [some of which are true, methinks]


<URL: http://www.google.com/search?q=not >
10,470,000,000 hits.

<URL: http://www.google.com/search?q=true >
Shows me 1,190,000,000 hits.


However Not is an unary operator and not a statement in itself, it needs
true or false for completion.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 19 '06 #18
Evertjan. said the following on 1/19/2006 6:28 PM:
Randy Webb wrote on 19 jan 2006 in comp.lang.javascript:
Evertjan. said the following on 1/19/2006 11:47 AM:
Matt Silberstein wrote on 19 jan 2006 in comp.lang.javascript:
Which makes me wonder what is the verifiably objectively wrong
statement with the largest number of Google hits?
"True"

"Not" :)
<http://www.google.com/search?q=true>

777,000,000 hits. [some of which are true, methinks]

<URL: http://www.google.com/search?q=not >
10,470,000,000 hits.

<URL: http://www.google.com/search?q=true >
Shows me 1,190,000,000 hits.


However Not is an unary operator and not a statement in itself, it needs
true or false for completion.


Why?

http://www.google.com/search?q=why
2,760,000,000 hits

But you are right about Not.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 20 '06 #19
Randy Webb wrote on 20 jan 2006 in comp.lang.javascript:
Why?

http://www.google.com/search?q=why
2,760,000,000 hits

But you are right about Not.


A negative expression, Randy.

Or was it ment to be:

"But you are right about Knot" ?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 20 '06 #20
Evertjan. said the following on 1/20/2006 9:08 AM:
Randy Webb wrote on 20 jan 2006 in comp.lang.javascript:
Why?

http://www.google.com/search?q=why
2,760,000,000 hits

But you are right about Not.

A negative expression, Randy.


It was? Wow.
Or was it ment to be:

"But you are right about Knot" ?


But you are right about "Not".

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 20 '06 #21

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

Similar topics

2
by: Paul Thompson | last post by:
I am trying to use various javascript tools, all of which work in NN, to work in IE. Here's my latest annoyance. I get a list of all objects on a page using docContents =...
3
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
5
by: den2005 | last post by:
Hi everybody, Problem with dragging effect of resizing is working but having problem with setting a flag to determine if mouse button is click or not. Is there anyone knows how to fixed this? I...
1
by: Nitu Kumar Patra | last post by:
I want to get the value of the to ,cc, bcc fields of hotmail in netscape browser using getElementsByName("to").value. But it is not working. How to retrieve these values can anyone tell me? Thanks
11
by: srini | last post by:
Frens, I am trying to get screen resolution of the client machine using javascript and use those values in my project. I looked at some of the examples given in this group, i tried to implement...
1
by: gsreenathreddy | last post by:
Hi! <html> <head> <script type="text/javascript"> function upperCase() { var x=document.getElementById("fname").value; document.getElementById("fname").value=x.toUpperCase(); }
22
by: azura | last post by:
dear sir..my friend give me one code how to calculate without pressing any button... but i didn't know how to insert function to make it work... very very newbie in calculation using...
28
by: shivasusan | last post by:
I don't know how to change the text box name? for ex:(my table like this) sl. country from to 1 aaa (txt_c1) 5/4/09 (txt_f1) 5/13/09 (txt_t1) // Now i delete this row. 2 bbb (txt_c2) 5/18/09...
41
by: elham477 | last post by:
I have two pages. The first page contain a table with title and the second contain texts & selected option. I want it so when a user in second page clicks the submit button, his information is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.