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 13 of 13
  1. #1
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts

    javascript scope

    I have a popup in one of my pages which is populated via AJAX call with a list of click-able options, this is all good, however I am now trying to display a javascript tree in the popup but it can not seem to 'see' the javascript routine that creates the tree, even if I hard code that into the popup itself, so the tree starts with d=new dTree() , and javasript is telling me that 'd' is undefined.

    the code works fine in a regular webpage but when pulled up in a AJAX generated popup it cant see squat? I tried parent.dTree() etc but to no avail.

    Is this because the javascript is loaded after the main page load via AJAX? if so is it accessible in anyway ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,764
    Thanks
    19
    Thanked 155 Times in 146 Posts
    In Firebug, do you see the AJAX-generated javascript? If so, can you paste it here? In fact, just paste everything source-related that you can find inside Firebug.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    hey cheers , yes I can, did not have firebug installed... now even more confused cos its all there...

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <body>
    <center>
    <div id="message_stick" style="position:absolute;top:100px;left:280px;width:500px;height:100px;border: 2px solid #696969;background-color:white;visibility:hidden;text-align:center;">
    <div id="centaur_popup" class="centaur_popup_as_usersel" style="position: absolute; display: block; visibility: visible;">
    here
    <script src="http://srv.blah.com.au/js/dtree.js" type="text/javascript">
    <div id="region_tree">
    <script type="text/javascript">
    d = new dTree('d');
    d.add(0,-1,'Logins','?FPA_TASK=fpa_regions_admin&_ctl_edit=1','','');
    d.add(1,0,'Tech Subcriptions','?FPA_TASK=fpa_regions_admin&_ctl_edit=3','','');
    d.add(2,1,'Skype','?FPA_TASK=fpa_regions_admin&_ctl_edit=2','','');
    d.add(3,0,'Server Logins','?FPA_TASK=fpa_regions_admin&_ctl_edit=4','','');
    d.add(4,3,'testserver2','?FPA_TASK=fpa_regions_admin&_ctl_edit=6','','');
    d.add(5,3,'blah.com','?FPA_TASK=fpa_regions_admin&_ctl_edit=5','','');
    document.write(d);
    </script>
    <a href="javascript: d.openAll();">open all</a>
    |
    <a href="javascript: d.closeAll();">close all</a>
    </div>
    </div>
    <table style="width:980px;">
    <br>
    <small></small>
    </center>
    </body>
    </html>
    now if I copy and paste the above into a regular HTML file , it works just fine, in the popup it shows me only the open and close links which if I click debugger says ...

    Timestamp: 20/05/12 19:27:40
    Error: d is not defined
    Source File: javascript:%20d.closeAll();
    Line: 1
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    weird thing is, I put a function testit() which just alerts a message in the dtree.js file and added an onclick in the ajax generated content and that works fine, e.g. testit()
    works

    Code:
    <div id="region_tree">
    <a href="javascript: testit();">test</a>    << HERE
    <script type="text/javascript">
    d = new parent.dTree('d');
    d.add(0,-1,'Logins','?FPA_TASK=fpa_regions_admin&_ctl_edit=1','','');
    d.add(1,0,'Tech Subcriptions','?FPA_TASK=fpa_regions_admin&_ctl_edit=3','','');
    d.add(2,1,'Skype','?FPA_TASK=fpa_regions_admin&_ctl_edit=2','','');
    d.add(3,0,'Server Logins','?FPA_TASK=fpa_regions_admin&_ctl_edit=4','','');
    d.add(4,3,'testserver2','?FPA_TASK=fpa_regions_admin&_ctl_edit=6','','');
    d.add(5,3,'blah.com.au','?FPA_TASK=fpa_regions_admin&_ctl_edit=5','','');
    document.write(d); 
    </script>

    this is the dtree.js btw ... http://destroydrop.com/javascripts/t...ample/dtree.js
    Last edited by firepages; 05-20-2012 at 01:22 PM.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,764
    Thanks
    19
    Thanked 155 Times in 146 Posts
    so this line of code:

    Code:
    <script src="http://srv.blah.com.au/js/dtree.js" type="text/javascript">
    is not a part of the ajax-generated content?
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,764
    Thanks
    19
    Thanked 155 Times in 146 Posts
    the problem might be:

    Code:
    document.write(d);
    try attaching the new content to your page via the DOM instead of via document.write()
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #7
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,764
    Thanks
    19
    Thanked 155 Times in 146 Posts
    also, where is the DOM object with id 'd' that corresponds to this statement:

    Code:
    d = new dTree('d');
    ..perhaps the element doesn't exist or has not loaded yet
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    Quote Originally Posted by chump2877 View Post
    so this line of code:

    Code:
    <script src="http://srv.blah.com.au/js/dtree.js" type="text/javascript">
    is not a part of the ajax-generated content?
    no, its already loaded on the initial page, though I have tried loading it within the ajax-gen content instead and also just adding the entire script into the ajax-gen content as well with no joy.

    d is just the returned object ID I assume , like $d=new $class

    .. i dont know enouigh about javascript to know how to get the content out of 'd' to do a DOM innerHTML call
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    again please note that the content shown above cut and pasted into a HTML page works without issue
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #10
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,764
    Thanks
    19
    Thanked 155 Times in 146 Posts
    i meant this 'd':

    Code:
    d = new dTree('d');
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #11
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    ah ok, thats just a unique id, so you could have several trees , d1=new dTree('d1'), etc
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #12
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,764
    Thanks
    19
    Thanked 155 Times in 146 Posts
    You are missing a closing script tag here:

    Code:
    <script src="http://srv.blah.com.au/js/dtree.js" type="text/javascript">
    I was troubleshooting the JS instead of the markup. You really should make sure that your markup is valid. It's pretty goofy in here:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <body>
    <center>
    <div id="message_stick" style="position:absolute;top:100px;left:280px;width:500px;height:100px;border: 2px solid #696969;background-color:white;visibility:hidden;text-align:center;">
    <div id="centaur_popup" class="centaur_popup_as_usersel" style="position: absolute; display: block; visibility: visible;">
    here
    <script src="http://srv.blah.com.au/js/dtree.js" type="text/javascript">
    <div id="region_tree">
    <script type="text/javascript">
    d = new dTree('d');
    d.add(0,-1,'Logins','?FPA_TASK=fpa_regions_admin&_ctl_edit=1','','');
    d.add(1,0,'Tech Subcriptions','?FPA_TASK=fpa_regions_admin&_ctl_edit=3','','');
    d.add(2,1,'Skype','?FPA_TASK=fpa_regions_admin&_ctl_edit=2','','');
    d.add(3,0,'Server Logins','?FPA_TASK=fpa_regions_admin&_ctl_edit=4','','');
    d.add(4,3,'testserver2','?FPA_TASK=fpa_regions_admin&_ctl_edit=6','','');
    d.add(5,3,'blah.com','?FPA_TASK=fpa_regions_admin&_ctl_edit=5','','');
    document.write(d);
    </script>
    <a href="javascript: d.openAll();">open all</a>
    |
    <a href="javascript: d.closeAll();">close all</a>
    </div>
    </div>
    <table style="width:980px;">
    <br>
    <small></small>
    </center>
    </body>
    </html>
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #13
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    yeah thats just a copy from firebug without the tree expaned to keep it short.. I will put something online and post back.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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