Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-29-2011, 02:44 AM   PM User | #1
malfdawg
New to the CF scene

 
Join Date: Jun 2011
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
malfdawg is an unknown quantity at this point
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???
malfdawg is offline   Reply With Quote
Old 06-29-2011, 07:03 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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.
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
malfdawg (06-29-2011)
Old 06-29-2011, 09:52 AM   PM User | #3
malfdawg
New to the CF scene

 
Join Date: Jun 2011
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
malfdawg is an unknown quantity at this point
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
malfdawg is offline   Reply With Quote
Old 06-29-2011, 10:22 AM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
You're welcome :-)
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:36 PM.


Advertisement
Log in to turn off these ads.