FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Javascript No properties defined problem?

 


flatliner
hi every1

Well I have a script that is loaded when the page loads, its inline on the page and it used getelementByid method.

Code:
document.getElementById("my_id")


The only problem is that the id for this script dont load into the page when the page loads, they are only requested if you click a button. I.E an ajax request loads them to the page, but my script is already broken because it couldnt find the id's on the frist load?

In the passed I have include the id's as hidden elements in the html document and when the ajax request loaded my actually content they were removed, just wondering is there an easyer way to do it?

I have try alots of things, like loading the script with the id's in the ajax request but still nothing.
Thanks
Stubru Freak
flatliner wrote:
hi every1

Well I have a script that is loaded when the page loads, its inline on the page and it used getelementByid method.

Code:
document.getElementById("my_id")


The only problem is that the id for this script dont load into the page when the page loads, they are only requested if you click a button. I.E an ajax request loads them to the page, but my script is already broken because it couldnt find the id's on the frist load?

In the passed I have include the id's as hidden elements in the html document and when the ajax request loaded my actually content they were removed, just wondering is there an easyer way to do it?

I have try alots of things, like loading the script with the id's in the ajax request but still nothing.
Thanks


Maybe make a function like this:
Code:

function safeGetElementById(id){
  if(document.getElementById(id))
    return document.getElementById(id);
  else
    return false;
}


When it returns false you know the content hasn't been loaded yet.
flatliner
Thanks for your reply, yes maybe that would work alright, but I found a very handy way and doesnt need more scriptting. In the box were the ajax would be placing the newly loaded content I put this code

Code:
<a class=\"hidden\" id=\"my_id\"></a>

etc

In the style sheet I set all these to hidden (so they were not displayed) and so the script was able to find the id's on the frist load and then when I would request the content via ajax the real elements with the id's on them would load in and the script wouldnt know the difference, ha.

Thanks
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.