document.getElementById("layer" + i) has no prperties

K

karsagarwal

Hi,

I am getting the error:

document.getElementById("layer" + i) has no prperties and have no
clue as to what it's not liking. Any inputs would be helpful....

I am including the code below:

Thanks!!

------------------------------------------------------------------------
function parseXML()
{
debugger;
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}

if (xmlDoc!=null)
{


xmlDoc.async=false;
xmlDoc.load("cnn_topstories.xml");
xtitle=xmlDoc.getElementsByTagName("title");
xdesc =xmlDoc.getElementsByTagName("description");
for (i=0;i<xtitle.length;i++) {
y=xtitle.childNodes[0].nodeValue;
z=xdesc.childNodes[0].nodeValue;
document.getElementById("layer" + i).innerHTML=y;
}
}
//
document.getElementById(i).innerHTML=xmlDoc.getElementsByTagName("item")
[0].childNodes[0].nodeValue;
//
document.getElementById("1").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("2").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("3").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("4").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;

}


</script>
</head>

<body>

<div id="rotate"><p>test</p>

<p><b>Item Title:</b><span id="layer0"; style="position:absolute; top:
0px; left:0px; width:50px; height:50px; background-color:red;
border:solid 1px white; vidibility:hidden "></span><br

/>
<span id="layer1"; style="position:absolute; top:20px; left:20px;
width:50px; height:50px; background-color:blue; border:solid 1px
white; "></span><br />
<span id="layer2"; style="position:absolute; top:40px; left:40px;
width:50px; height:50px; background-color:green; border:solid 1px
white; "></span><br />
<span id="layer3"; style="position:absolute; top:50px; left:50px;
width:50px; height:50px; background-color:purple; border:solid 1px
white; "></span><br />
<span id="layer4"; style="position:absolute; top:60px; left:60px;
width:50px; height:50px; background-color:yellow; border:solid 1px
white; "></span><br />

</div>

<SCRIPT type="text/javascript">parseXML() </script>

-->
</body>
 
T

Tom de Neef

I am getting the error:

document.getElementById("layer" + i) has no prperties and have no
clue as to what it's not liking. Any inputs would be helpful....

I am including the code below:

Thanks!!

------------------------------------------------------------------------
function parseXML()
{
debugger;
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}

if (xmlDoc!=null)
{


xmlDoc.async=false;
xmlDoc.load("cnn_topstories.xml");
xtitle=xmlDoc.getElementsByTagName("title");
xdesc =xmlDoc.getElementsByTagName("description");
for (i=0;i<xtitle.length;i++) {
y=xtitle.childNodes[0].nodeValue;
z=xdesc.childNodes[0].nodeValue;
document.getElementById("layer" + i).innerHTML=y;
}
}
//
document.getElementById(i).innerHTML=xmlDoc.getElementsByTagName("item")
[0].childNodes[0].nodeValue;
//
document.getElementById("1").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("2").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("3").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("4").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;

}


</script>
</head>

<body>

<div id="rotate"><p>test</p>

<p><b>Item Title:</b><span id="layer0"; style="position:absolute; top:
0px; left:0px; width:50px; height:50px; background-color:red;
border:solid 1px white; vidibility:hidden "></span><br

/>
<span id="layer1"; style="position:absolute; top:20px; left:20px;
width:50px; height:50px; background-color:blue; border:solid 1px
white; "></span><br />
<span id="layer2"; style="position:absolute; top:40px; left:40px;
width:50px; height:50px; background-color:green; border:solid 1px
white; "></span><br />
<span id="layer3"; style="position:absolute; top:50px; left:50px;
width:50px; height:50px; background-color:purple; border:solid 1px
white; "></span><br />
<span id="layer4"; style="position:absolute; top:60px; left:60px;
width:50px; height:50px; background-color:yellow; border:solid 1px
white; "></span><br />

</div>

<SCRIPT type="text/javascript">parseXML() </script>

-->
</body>


I would guess that the function parseXML() is called before the document is
built into a DOM structure.
You can verify this by removing that last <script> line in the <body> and
call from
<body onload="parseXML()">

And what does the comment close tag "-->" just prior to </body> do there?
Tom
 
K

karsagarwal

<[email protected]>




I am getting the error:
document.getElementById("layer" + i) has no prperties and have no
clue as to what it's not liking. Any inputs would be helpful....
I am including the code below:

------------------------------------------------------------------------
function parseXML()
{
debugger;
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("cnn_topstories.xml");
xtitle=xmlDoc.getElementsByTagName("title");
xdesc =xmlDoc.getElementsByTagName("description");
for (i=0;i<xtitle.length;i++) {
y=xtitle.childNodes[0].nodeValue;
z=xdesc.childNodes[0].nodeValue;
document.getElementById("layer" + i).innerHTML=y;
}
}
//
document.getElementById(i).innerHTML=xmlDoc.getElementsByTagName("item")
[0].childNodes[0].nodeValue;
//
document.getElementById("1").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("2").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("3").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
//
document.getElementById("4").innerHTML=xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
</script>
</head>

<div id="rotate"><p>test</p>

<p><b>Item Title:</b><span id="layer0"; style="position:absolute; top:
0px; left:0px; width:50px; height:50px; background-color:red;
border:solid 1px white; vidibility:hidden "></span><br
/>
<span id="layer1"; style="position:absolute; top:20px; left:20px;
width:50px; height:50px; background-color:blue; border:solid 1px
white; "></span><br />
<span id="layer2"; style="position:absolute; top:40px; left:40px;
width:50px; height:50px; background-color:green; border:solid 1px
white; "></span><br />
<span id="layer3"; style="position:absolute; top:50px; left:50px;
width:50px; height:50px; background-color:purple; border:solid 1px
white; "></span><br />
<span id="layer4"; style="position:absolute; top:60px; left:60px;
width:50px; height:50px; background-color:yellow; border:solid 1px
white; "></span><br />

<SCRIPT type="text/javascript">parseXML() </script>
-->
</body>

I would guess that the function parseXML() is called before the document is
built into a DOM structure.
You can verify this by removing that last <script> line in the <body> and
call from
<body onload="parseXML()">

And what does the comment close tag "-->" just prior to </body> do there?
Tom


Hi Tom,

Well I tried <body onload="parseXML()"> but it is still gives me same
error message: document.getElementById("layer" + i) has no properties.


Regarding the comment close tag:
I have multiple span statement and so I just commented all except one
to test it out.

If you see the light let me know.

Thanks,
AA
 
T

Tom de Neef

Well I tried <body onload="parseXML()"> but it is still gives me same
error message: document.getElementById("layer" + i) has no properties.


Regarding the comment close tag:
I have multiple span statement and so I just commented all except one
to test it out.

1) But it is not obvious to me which ones you have commented out. What if
all are commented out?

2) In your code:
for (i=0;i<xtitle.length;i++) {
y=xtitle.childNodes[0].nodeValue;
z=xdesc.childNodes[0].nodeValue;
document.getElementById("layer" + i).innerHTML=y;

i runs thru the xtitle array. It is not obvious that there is a
corresponding "layer"+i id for all those i. Doesn't the error message say
no attributes for ... "layer1" ?

3) With FF+Firebug you can inspect the values of variables while running
your code. It'd be easy to see what value i has when the error is thrown.

Tom
 
S

SAM

(e-mail address removed) a écrit :
Hi,

I am getting the error:

document.getElementById("layer" + i) has no prperties and have no
clue as to what it's not liking. Any inputs would be helpful....

I am including the code below:

I see no tag 'title' in your code
so what could do :
xtitle=xmlDoc.getElementsByTagName("title");
and further :
for (i=0;i<xtitle.length;i++) {

Try :

if(!document.getElementById("layer" + i))
alert('layer #'+i+' not possible');
else
document.getElementById("layer" + i).innerHTML=y;

to see how much more titles than spans you have
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top