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

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 12-20-2007, 12:15 PM   PM User | #1
alapimba
Regular Coder

 
Join Date: Jul 2006
Posts: 117
Thanks: 1
Thanked 0 Times in 0 Posts
alapimba is an unknown quantity at this point
how to call 2 funcions on click?

Hello
I'm with a few problems with some functions.
It works if i have only one, but when i write the second an call it it don't work.

My function:
Code:
<?php do { $numero = $row_rs_anos['id']; ?>
function titulo<?php echo $numero ?>() {
 http.open("GET", "titulo<?php echo $numero ?>.html", true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById('titulo').innerHTML = http.responseText;
	  initLightbox();
    }
  }
  http.send(null);
}  
function replace<?php echo $numero ?>() {
  http.open("GET", "teste<?php echo $numero ?>.html", true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById('imgs').innerHTML = http.responseText;
	  initLightbox();
    }
  }
  http.send(null);
}

<?php } while ($row_rs_anos = mysql_fetch_assoc($rs_anos)); ?>
as you see the funcione titulo and the function replace are basicly the same, just change the page they open from and the div where it will appear.. i don't know if i should write it twice as i did or theres any better way..

I'm calling it with:
Code:
<a href="javascript:replace<?php echo $row_rs_anos2['id']; ?>(); titulo<?php echo $row_rs_anos2['id']; ?>()"><?php echo $row_rs_anos2['ano'];  ?></a>
What i'm doing wrong and how to fix it?
Thanks
alapimba is offline   Reply With Quote
Old 12-20-2007, 09:58 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
It's a tricky way to send 2 requests nearly at the same time. Have you tried to call the second function after the first gets it's response?
Code:
function replace<?php echo $numero ?>() {
  http.open("GET", "teste<?php echo $numero ?>.html", true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById('imgs').innerHTML = http.responseText;
	  initLightbox();
titulo<?php echo $numero ?>();
    }
  }
  http.send(null);
}
and:
Code:
<a href="#" onclick="replace<?php echo $row_rs_anos2['id']; ?>();return false"><?php echo $row_rs_anos2['ano'];  ?></a>
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 12-20-2007, 11:10 PM   PM User | #3
alapimba
Regular Coder

 
Join Date: Jul 2006
Posts: 117
Thanks: 1
Thanked 0 Times in 0 Posts
alapimba is an unknown quantity at this point
yeah that way it works.
Thanks
alapimba 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 12:59 PM.


Advertisement
Log in to turn off these ads.