Bob Z
Bob Z

Reputation: 19

Can't get text into variable from XML files using javascript

I have been banging my head over this (probably simple) issue and am missing something really basic. Why does this first code display the expected output

xmlhttp=xmlhttp.responseXML;

document.getElementById("CenterDataBox").innerHTML= xmlhttp.getElementsByTagName("ShowDay")[0].childNodes[0].nodeValue;

and this second one doesn't? I think this is something really simple I've overlooking.

xmlhttp=xmlhttp.responseXML;

var DayOfShow = xmlhttp.getElementsByTagName("ShowDay")[0].childNodes[0].nodeValue;
document.getElementById("CenterDataBox").innerHTML= DayofShow;

Upvotes: 0

Views: 68

Answers (3)

jhorapb
jhorapb

Reputation: 736

The error is that your variable DayOfShow is not what you're using. You're using DayofShow, without capital '0' letter.

Upvotes: 1

Nejc Rodošek
Nejc Rodošek

Reputation: 163

You got mispelling of set variable. In example 2 i assume you're getting error var not defined. That is because you set value to DayOfShow and below you set inner html to DayofShow. Javascript is case sensitive.

Here you can read more about JS.

Upvotes: 0

StackSlave
StackSlave

Reputation: 10627

JavaScript is case-sensitive.

= DayofShow should be = DayOfShow in example 2.

Upvotes: 1

Related Questions