jnjk Posted November 6, 2006 Share Posted November 6, 2006 I am having problems populating multiple divs with different content. I have an array that contains a url with two different parameters. The html contains two divs with the id's updateArea0 and updateArea1. The result I get is that only updateArea1 is populated with the results of the second array element. Here is the code.[code]window.onload = initAll;var xhr = null;var categories = new Array("ajax.php?cats=engines", "ajax.php?cats=computers");function initAll() { for(var i=0; i<2; i++) { getNewFile(categories[i],i); }}function getNewFile(url,i) { makeRequest(url,1); return false;}function makeRequest(url,i) { if(window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { if(window.ActiveXObject) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} } } if(xhr) { xhr.onreadystatechange = function() { showContents(i) }; xhr.open("GET",url,true); xhr.send(null); } else { document.getElementById("updateArea").innerHTML = "Sorry but the data is unavailable"; }}function showContents(i) { x = i + 7; currDiv = "updateArea" + i; if(xhr.readyState == 4) { if(xhr.status == 200) { var outMsg = (xhr.responseXML && xhr.responseXML.contentType == "text/xml") ? xhr.responseXML.getElementsById("choices")[0].textContent : xhr.responseText; } else { var outMsg = "There was a problem with the request " + xhr.status; } elem = document.getElementById(currDiv); elem.innerHTML = outMsg; }}[/code]Thanks in advance. Quote Link to comment Share on other sites More sharing options...
ober Posted November 6, 2006 Share Posted November 6, 2006 To update x different divs, you need to create x different objects. Each has it's own "update" function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.