469,332 Members | 6,821 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

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 3521
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Pieter Van Waeyenberge | last post: by
4 posts views Thread by dal.luc | last post: by
7 posts views Thread by lukaszmn | last post: by
3 posts views Thread by hantechs | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.