View Full Version : Referring by Elements ID problem

01-19-2009, 03:41 PM

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

This is my code.

function handleServerResponse479()
var configdisplay=document.getElementById('configdisplay').value;

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

}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

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

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