Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2008, 04:43 AM   PM User | #1
Uberbot
New to the CF scene

 
Join Date: Dec 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Uberbot is an unknown quantity at this point
Angry Can't get getElementsByTagName() to work

I'm trying to do a proof of concept and I'm having difficulty. I've reduced the code to the bare minimum.

I'm expecting 3 alerts indicating the id's of the 3 <p>'s in the html page. I'm getting the same message all 3 times:
"I am 0 test_p1"
"I am 1 test_p1"
"I am 2 test_p1"

Here is the code:

<body>
<p id="test_p1" m="testme">This is some text</p>
<p id="test_p2" m="xxx">This is some text</p>
<p id="test_p3" m="testme">This is some text</p>

<script>

function do_test () {
var i=0;

var e = document.getElementsByTagName("p");

for (i=0; i<e.length; i++) {
alert("I am "+i+" "+e[i].id);
}
}

do_test();

</script>
</body>
</html>
Uberbot is offline   Reply With Quote
Old 12-07-2008, 04:49 AM   PM User | #2
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
Could you provide a link instead?

The snippet you've shown works/alerts fine.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Old 12-07-2008, 05:32 AM   PM User | #3
Uberbot
New to the CF scene

 
Join Date: Dec 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Uberbot is an unknown quantity at this point
Doh!

I think I must have done something stupid. When I moved it to a openly accessible directory of my webspace, it worked.... I think I can fix it from here. Thanks for the help.

Uberbot is offline   Reply With Quote
Old 12-07-2008, 05:43 AM   PM User | #4
Uberbot
New to the CF scene

 
Join Date: Dec 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Uberbot is an unknown quantity at this point
...but not in a frame...

Well, the code does work when it's in a normal page, but when I put the page in a <frame>, it breaks. I know frames are frowned upon, but I have to do it this way. Can anyone think of a reason the SAME FILE doesn't work in a frame?

TIA,
Uberbot is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:46 AM.


Advertisement
Log in to turn off these ads.