Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Referring by Elements ID problem

    Hello,

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

    This is my code.

    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

    Code:
    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

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,854
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Could you post a link to your page? Is there any other element having the same id?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Reading your code, try to alert if the second index of helloMessage2 variable is asstype3:
    Code:
    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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •