Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Numerous functions to change different div content
Old 07-02-2010, 04:27 PM Numerous functions to change different div content
Experienced Talker

Posts: 31
Trades: 0
Hello again, I put in some ajax code, and am calling two different functions when a div is clicked. What it is supposed to do is replace two different divs content on the page. For example, when the button is clicked, it will change a div on the left to display "Left text", and the div on the right to display "right text". When I click the button, it just executes one of the functions into both divs, and displays "right text" into both of the div's.. Does anyone know what I am doing wrong? I hope this is enough information.. Thanks for any help!

Here's my code:

HTML Code:
<div id="div1" onclick="viewUpdates(); UpdatesTools();">Updates</div>
PHP Code:
function viewUpdates()
{
if (
window.XMLHttpRequest)
  {
// code for IE7+, Firefox, Chrome, Opera, Safari
  
xmlhttp=new XMLHttpRequest();
  }
else
  {
// code for IE6, IE5
  
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (
xmlhttp.readyState==&& xmlhttp.status==200)
    {
    
document.getElementById("other").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","page.php",true);
xmlhttp.send();
}

function 
UpdatesTools()
{
if (
window.XMLHttpRequest)
  {
// code for IE7+, Firefox, Chrome, Opera, Safari
  
xmlhttp=new XMLHttpRequest();
  }
else
  {
// code for IE6, IE5
  
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (
xmlhttp.readyState==&& xmlhttp.status==200)
    {
    
document.getElementById("rightbodytools").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","page2.php",true);
xmlhttp.send();

-Dillon

Last edited by Dillon; 07-02-2010 at 04:31 PM..
Dillon is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-02-2010, 04:43 PM Re: Numerous functions to change different div content
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.webmaster-talk.com/javasc...tml#post990137
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-02-2010, 05:02 PM Re: Numerous functions to change different div content
Experienced Talker

Posts: 31
Trades: 0
Oh ok, where do I put that code?

Thanks,
-Dillon
Dillon is offline
Reply With Quote
View Public Profile
 
Old 07-02-2010, 05:14 PM Re: Numerous functions to change different div content
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You use that code to replace the usual instantiation of the xml object.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-02-2010, 06:57 PM Re: Numerous functions to change different div content
Experienced Talker

Posts: 31
Trades: 0
Hello, I dont really understand... How could I integrate that code into this?

PHP Code:
function viewUpdates()
{
if (
window.XMLHttpRequest)
  {
// code for IE7+, Firefox, Chrome, Opera, Safari
  
xmlhttp=new XMLHttpRequest();
  }
else
  {
// code for IE6, IE5
  
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (
xmlhttp.readyState==&& xmlhttp.status==200)
    {
    
document.getElementById("other").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","page.php",true);
xmlhttp.send();
}

function 
UpdatesTools()
{
if (
window.XMLHttpRequest)
  {
// code for IE7+, Firefox, Chrome, Opera, Safari
  
xmlhttp=new XMLHttpRequest();
  }
else
  {
// code for IE6, IE5
  
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (
xmlhttp.readyState==&& xmlhttp.status==200)
    {
    
document.getElementById("rightbodytools").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","page2.php",true);
xmlhttp.send();

Thanks,
-Dillon
Dillon is offline
Reply With Quote
View Public Profile
 
Old 07-03-2010, 12:32 PM Re: Numerous functions to change different div content
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Instead of having this code
Code:
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("other").innerHTML=xmlhttp.responseText;
    }
  }
duplicated several times, you simply call setRequestObject(), then set the parameters for l_oRequest
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Numerous functions to change different div content
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40728 seconds with 12 queries