Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

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 05-19-2004, 05:29 PM   PM User | #1
deadseasquirrel
Regular Coder

 
Join Date: Feb 2004
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
deadseasquirrel is an unknown quantity at this point
Don't understand why alert(x) will work but not test = x not

My code is as follows (a snippet):
Code:
var newCity;
var newCenterName;

newCity = center.getElementsByTagName("city")[0].firstChild.nodeValue);
newCenterName = center.getElementsByTagName("name")[0].firstChild.nodeValue);
That above code does not work, but if I do:

alert(center.getElementsByTagName("city")[0].firstChild.nodeValue);
alert(center.getElementsByTagName("name")[0].firstChild.nodeValue);

works and it outputs the text. I am trying to save the text so I can use it in my javascript. But i am a real newbie at this XML stuff, can somebody give me a hand?
deadseasquirrel is offline   Reply With Quote
Old 05-19-2004, 11:40 PM   PM User | #2
Alex Vincent
Moderator


 
Join Date: May 2002
Location: Hayward, CA
Posts: 1,427
Thanks: 1
Thanked 19 Times in 17 Posts
Alex Vincent is on a distinguished road
Well, your code is correct... and incomplete.

You see, you set the newCity and newCenterName variables. But you didn't do anything with them. Try, just as a quick test:

alert(newCity + "\n" + newCenterName);

Set this after your

newCenterName = center...
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary
https://alexvincent.us/blog
Alex Vincent is offline   Reply With Quote
Old 05-20-2004, 04:30 AM   PM User | #3
deadseasquirrel
Regular Coder

 
Join Date: Feb 2004
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
deadseasquirrel is an unknown quantity at this point
I am not around my main computer, and I'll definitely try what you said in the morning. Even so, if you are right, it will mean there is a fundamental misunderstanding that I have of DOMs and javascripts.

Doesn't the line that writes:
newCity = center.getElementsByTagName("city")[0].firstChild.nodeValue);
newCenterName = center.getElementsByTagName("name")[0].firstChild.nodeValue);

do anything? I mean to me it looks like I am setting that variable to the nodeValues of those nodes.
deadseasquirrel is offline   Reply With Quote
Old 05-20-2004, 11:41 AM   PM User | #4
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
You have a syntax error there:

newCity = center.getElementsByTagName("city")[0].firstChild.nodeValue);
newCenterName = center.getElementsByTagName("name")[0].firstChild.nodeValue);
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 05-20-2004, 01:12 PM   PM User | #5
deadseasquirrel
Regular Coder

 
Join Date: Feb 2004
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
deadseasquirrel is an unknown quantity at this point
hmm...I was so concerned about my understanding of DOM that I forgot the simple stuff.
deadseasquirrel 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:23 PM.


Advertisement
Log in to turn off these ads.