Balagi Posted February 13, 2007 Share Posted February 13, 2007 So I have an object that I defined in my main page. I'd like to be able to use that object in a page I load into a DIV with AJAX. I'm relatively new with JS OOP and Ajax so I don't even know if this is possible. Here's an example: index.php <script type="text/javascript"> function DB(element, num) { this.element = element; this.num = num; this.loadDB = function() { // load ajax library - i use Prototype new Ajax.Updater('database', 'url/to/database.php'); } this.loadDB(); } window.onload = function() { DB = new DB('test', 101); } </script> <div id="database"> </div> database.php // this page is loaded into the "database" DIV on index.php <a href="javascript:void(0);" onclick="javascript:alert(DB.element);">Show value of DB.element</a> Obviously that is just a sample, I got my database.php page loading fine, I'd like to be able to use my previously defined object/variables from the database.php page. If this isn't possible, is there a better alternative other than creating a new object with the onclick event and losing my previously defined members? Thank you. Quote Link to comment Share on other sites More sharing options...
Balagi Posted February 14, 2007 Author Share Posted February 14, 2007 Nevermind, I got what I wanted to work. It was a combination of defining the object in the onload function and a never ending javascript loop that I completely overlooked. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.