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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Nested page; function calls

    Hello I am using a small, simple script to update a content box labeled contentDiv. To call the function I am using a link on my homepage (index.htm) which looks like the following:
    Code:
    <a class="" href="#" onclick="loadXMLDoc(0)">featured</a>
    And here is my js function:
    Code:
    function loadXMLDoc(DocNum)
    {
    	DocNames=['../content/featured.php','../content/news.php','../content/projects.php','../content/nomads.php','../content/rfrancis.php'];
    	MyDoc=DocNames[DocNum];
    var xmlhttp;
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest();
      }
    else
      {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("contentDiv").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET", MyDoc ,true);
    xmlhttp.send();
    }
    So far all of this works perfectly, so this is where I'm getting stuck. Let us assume I clicked the 'featured' link above and my contentDiv area changed to the content within featured.php. Is it possible or how would I go about making a link within the featured.php page to the SAME area (contentDiv)?

    Example:
    I click the link to load featured.php into contentDiv, and within featured.php is yet another link which can change contentDiv to anyother.php... Possible???

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    yes ... you should have onclick="loadXMLDoc(...)" for the link in featured.php and then you need anyother.php in the DocNames array and use its index for the loadXMLDoc call.

    Once loaded the result/content of featured.php has the same context / DOM as index.htm ... so you are still on index.htm and you can use its javascript function loadXMLDoc() from there.

  • Users who have thanked devnull69 for this post:

    malfdawg (06-29-2011)

  • #3
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    yes I see... because css works this way I assumed it were true for javascript as well, I only ended up here because I didnt think it was working... maybe I didnt check all my spelling or something... well I'll try again. Thank you devnull69, you seem to be the one who always helps me! =D

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    You're welcome :-)


  •  

    Posting Permissions

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