...

View Full Version : Don't understand why alert(x) will work but not test = x not



deadseasquirrel
05-19-2004, 05:29 PM
My code is as follows (a snippet):


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?

Alex Vincent
05-19-2004, 11:40 PM
:o 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...

deadseasquirrel
05-20-2004, 04:30 AM
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.

liorean
05-20-2004, 11:41 AM
You have a syntax error there:

newCity = center.getElementsByTagName("city")[0].firstChild.nodeValue);
newCenterName = center.getElementsByTagName("name")[0].firstChild.nodeValue);

deadseasquirrel
05-20-2004, 01:12 PM
hmm...I was so concerned about my understanding of DOM that I forgot the simple stuff.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum