...

View Full Version : Referring by Elements ID problem



agravayne
01-19-2009, 03:41 PM
Hello,

I have a very strange problem with referring to a page element by ID

This is my code.


function handleServerResponse479()
{if(xmlHttp.readyState==4){if(xmlHttp.status==200){
document.getElementById("roller").style.display="none";
helloMessage=xmlHttp.responseText;
var configdisplay=document.getElementById('configdisplay').value;
dhxWins.window("editasset").close();
helloMessage2=helloMessage.split("~");

var p=document.getElementById(helloMessage2[1]);
p.innerHTML=helloMessage2[0];

}else{alert("There was a problem accessing the server: "+xmlHttp.statusText);}}}

It gives an error saying that p.has no properties - that it cannot find the id held in the variable helloMessage2[1]. In the example I am testing this is asstype3 confirmed by adding an alert. If I change the line to


var p=document.getElementById('asstype3');

it works fine! Any ideas why its not accepting a javascript variable as the ID? I have used the same peice of code elsewhere and it works fine. Its driving me nuts.

Many thanks
Scott

abduraooft
01-20-2009, 08:44 AM
Could you post a link to your page? Is there any other element having the same id?

rangana
01-20-2009, 10:17 AM
Reading your code, try to alert if the second index of helloMessage2 variable is asstype3:


alert(helloMessage2[1]); // Should alert asstype3
var p=document.getElementById(helloMessage2[1]);


If it's not asstype3, then you already know the cause.

Additionally, please let us know the value of helloMessage var.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum