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 11-05-2007, 03:57 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
simple ajax replace but with many links

Hello, can anyone help me with this function?

i'm doing a replace, the content appears inside the div "foo".

now i want to have like 3 or 4 links with the funcione replace and each one replace his own content.

my code so far and working is:

Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
} 
function replace() {
  http.open("GET", "conteudo.php?id=1", true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById('foo').innerHTML = http.responseText;
    }
  }
  http.send(null);
}
</script> 
 
</head>
<body>
<div class="accordion_content">
    <h2><p><a href="javascript:replace()">link 1</a></p>
<div id="foo">
  here appear the content
</div></h2>
</body>
alapimba is offline   Reply With Quote
Old 11-06-2007, 04:51 AM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
use function parameters
Code:
function replace(where, what) {
  http.open("GET", "conteudo.php?id=" + what, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById(where).innerHTML = http.responseText;
    }
  }
  http.send(null);
}
Code:
<a href="javascript:replace('foo', 1)">link 1</a>
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote
Old 11-06-2007, 11:53 AM   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
thank you
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 11:24 PM.


Advertisement
Log in to turn off these ads.