472,331 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

document.getElementsByName problem

<html>
<head>
<script language="vbscript">
sub window_onload
msgbox document.getElementsByName("name1").length
end sub
</script>
</head>
<body>
<div name="name1">testDiv</div>
<table id="tbl1" name="name1"><tr><td>table1</td></tr></table>
<table id="tbl2"
name="name1"><tbody><tr><td>table2</td></tr></tbody></table>
</body>
</html>

Why document.getElementsByName("name1") returns always 0 ? I have 3 elements
with name property="name1"

Does anybody know the answer?

Is there any other way to join this 3 elements?

I have about 1000 table elements on the page and I don't want to use
function document.getElementsByTagName.

Thank you,
Simon
Nov 19 '05 #1
5 3611
Simon,

Could be the elements are not parsed by the browser yet when window's onload
event fires. Just for testing, make an onclick event for any of the elements
and produce the messagebox there.

Eliyahu

"simon" <si*********@stud-moderna.si> wrote in message
news:eD**************@TK2MSFTNGP10.phx.gbl...
<html>
<head>
<script language="vbscript">
sub window_onload
msgbox document.getElementsByName("name1").length
end sub
</script>
</head>
<body>
<div name="name1">testDiv</div>
<table id="tbl1" name="name1"><tr><td>table1</td></tr></table>
<table id="tbl2"
name="name1"><tbody><tr><td>table2</td></tr></tbody></table>
</body>
</html>

Why document.getElementsByName("name1") returns always 0 ? I have 3 elements with name property="name1"

Does anybody know the answer?

Is there any other way to join this 3 elements?

I have about 1000 table elements on the page and I don't want to use
function document.getElementsByTagName.

Thank you,
Simon

Nov 19 '05 #2
Thank you for your answer.

Even if I execute the msgbox with click event, still the same problem

Thanks,
Simon

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:uZ****************@TK2MSFTNGP10.phx.gbl...
Simon,

Could be the elements are not parsed by the browser yet when window's
onload
event fires. Just for testing, make an onclick event for any of the
elements
and produce the messagebox there.

Eliyahu

"simon" <si*********@stud-moderna.si> wrote in message
news:eD**************@TK2MSFTNGP10.phx.gbl...
<html>
<head>
<script language="vbscript">
sub window_onload
msgbox document.getElementsByName("name1").length
end sub
</script>
</head>
<body>
<div name="name1">testDiv</div>
<table id="tbl1" name="name1"><tr><td>table1</td></tr></table>
<table id="tbl2"
name="name1"><tbody><tr><td>table2</td></tr></tbody></table>
</body>
</html>

Why document.getElementsByName("name1") returns always 0 ? I have 3

elements
with name property="name1"

Does anybody know the answer?

Is there any other way to join this 3 elements?

I have about 1000 table elements on the page and I don't want to use
function document.getElementsByTagName.

Thank you,
Simon


Nov 19 '05 #3
Try around :
http://msdn.microsoft.com/workshop/a...ies/name_2.asp

It looks like the name attribute doesn't exists for the TABLE tag. It would
make here "name" a custom attribute ignored by getElementsByName...
Patrice

--

"simon" <si*********@stud-moderna.si> a écrit dans le message de
news:eD**************@TK2MSFTNGP10.phx.gbl...
<html>
<head>
<script language="vbscript">
sub window_onload
msgbox document.getElementsByName("name1").length
end sub
</script>
</head>
<body>
<div name="name1">testDiv</div>
<table id="tbl1" name="name1"><tr><td>table1</td></tr></table>
<table id="tbl2"
name="name1"><tbody><tr><td>table2</td></tr></tbody></table>
</body>
</html>

Why document.getElementsByName("name1") returns always 0 ? I have 3 elements with name property="name1"

Does anybody know the answer?

Is there any other way to join this 3 elements?

I have about 1000 table elements on the page and I don't want to use
function document.getElementsByTagName.

Thank you,
Simon

Nov 19 '05 #4
getElementsByName only works for form elements (<input>,<select>, and
<textarea>). to access any html element use getElementById

<html>
<head>
<script language="vbscript">
sub window_onload
msgbox document.getElementByName("name1").innerHTML
end sub
</script>
</head>
<body>
<div id="name1">testDiv</div>
<table id="tbl1" name="name1"><tr><td>table1</td></tr></table>
<table id="tbl2"
name="name1"><tbody><tr><td>table2</td></tr></tbody></table>
</body>
</html>

"simon" <si*********@stud-moderna.si> wrote in message
news:eD**************@TK2MSFTNGP10.phx.gbl...
<html>
<head>
<script language="vbscript">
sub window_onload
msgbox document.getElementsByName("name1").length
end sub
</script>
</head>
<body>
<div name="name1">testDiv</div>
<table id="tbl1" name="name1"><tr><td>table1</td></tr></table>
<table id="tbl2"
name="name1"><tbody><tr><td>table2</td></tr></tbody></table>
</body>
</html>

Why document.getElementsByName("name1") returns always 0 ? I have 3
elements with name property="name1"

Does anybody know the answer?

Is there any other way to join this 3 elements?

I have about 1000 table elements on the page and I don't want to use
function document.getElementsByTagName.

Thank you,
Simon

Nov 19 '05 #5
Hi,

thank you for your answers.
Is there some other way to get the array of tables if getElementsByName
doesn't work for tables?

regards,
Simon

"Bruce Barker" <br******************@safeco.com> wrote in message
news:eP**************@TK2MSFTNGP15.phx.gbl...
getElementsByName only works for form elements (<input>,<select>, and
<textarea>). to access any html element use getElementById

<html>
<head>
<script language="vbscript">
sub window_onload
msgbox document.getElementByName("name1").innerHTML
end sub
</script>
</head>
<body>
<div id="name1">testDiv</div>
<table id="tbl1" name="name1"><tr><td>table1</td></tr></table>
<table id="tbl2"
name="name1"><tbody><tr><td>table2</td></tr></tbody></table>
</body>
</html>

"simon" <si*********@stud-moderna.si> wrote in message
news:eD**************@TK2MSFTNGP10.phx.gbl...
<html>
<head>
<script language="vbscript">
sub window_onload
msgbox document.getElementsByName("name1").length
end sub
</script>
</head>
<body>
<div name="name1">testDiv</div>
<table id="tbl1" name="name1"><tr><td>table1</td></tr></table>
<table id="tbl2"
name="name1"><tbody><tr><td>table2</td></tr></tbody></table>
</body>
</html>

Why document.getElementsByName("name1") returns always 0 ? I have 3
elements with name property="name1"

Does anybody know the answer?

Is there any other way to join this 3 elements?

I have about 1000 table elements on the page and I don't want to use
function document.getElementsByTagName.

Thank you,
Simon


Nov 19 '05 #6

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

Similar topics

3
by: Pieter Van Waeyenberge | last post by:
Hello, im some image elements using doc.createElement('IMG'); i set the following styles: - for the images container: white-space:normal; - for...
4
by: Tauqir | last post by:
I am trying to do a simple thing: I have these two text fields in an HTML form. I want to assign the concatenated value to a TEXTAREA. Can someone...
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...
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...
4
by: dal.luc | last post by:
Hello, I've a problem : I want to check which element has been checked in a list of radiobuttons. /////////////////////////////////////...
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...
3
by: hantechs | last post by:
Hi, all I found I can get the img element named with "image1" in a html by using "document.image1" with javascript. It's very convenient because...
11
Dormilich
by: Dormilich | last post by:
I want to add (prototype) a method to the node list returned by document.getElementsByName() (and related, i.e. NodeList resp. HTMLCollection). ...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.