Avatar of hornbill

asked on 

Update 2 divs with one onclick event

New to ajax and have been using the following script to update the contents of a single div with separate onclick events. Now I would like to know how to modify the script to handle updates to both (or more) divs with a SINGLE onclick event? Thanks.
<script language="javascript">
var ajaxdestination="";
function getdata(what,where) { // get data from source (what)
	 try {
   xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
	 catch (e) { /* do nothing */ }
 		document.getElementById(where).innerHTML ="<center><img src='loading.gif'></center>";
// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
 	xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
 	xmlhttp.open("GET", what);
  return false;
function triggered() { // put data returned by requested URL to selected DIV
  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
<a href="#" onclick="getdata('FileA.php','content1');">Click to update Box 1</a>
<a href="#" onclick="getdata('FileB.php','content2');">Click to update Box 2</a>
<div id="content1">Box 1 Contents</div>
<div id="content2">Box 2 Contents</div>

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon