pingu Posted May 13, 2008 Share Posted May 13, 2008 Hi, very new to AJAX here, so forgive any glaring idiocy below. I've got a drop down menu that onChange, needs to populate a table and also another drop down menu. The data is returned by two different PHP scripts. I can get the following script to populate on or the other item, but not at the same time. Rather annoyingly I did have it working, but the tidied up the code and broke it and I can't figure out how! The offending function is the clientfilterAction() which is the function called by the onChange handler of the drop down menu. Can anyone point me towards where I'm going wrong? // Get the HTTP Object function getHTTPObject(){ var httpObject = null; if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) return new XMLHttpRequest(); else { alert("Your browser does not support AJAX."); return null; } } // Called by menu onChange, sends request to PHP script function clientfilterAction(){ // Set up and populate the job menu httpObject = getHTTPObject(); if (httpObject != null) { var url="../ajax-modules/job-menu.php"; url=url+"?CLIENTID="+document.getElementById('clientfiltermenu').value; url=url+"&sid="+Math.random(); httpObject.onreadystatechange = populateJobMenu; httpObject.open("GET", url, true); httpObject.send(null); } else { alert ("Browser does not support HTTP Request") return } // Set up and populate the tape listing for all the clients tapes httpObject = getHTTPObject(); alert(httpObject.responseText) if (httpObject != null) { var url="../ajax-modules/list-tapes.php"; url=url+"?CLIENTID="+document.getElementById('clientfiltermenu').value; url=url+"&sid="+Math.random(); httpObject.onreadystatechange = populateTapeList; httpObject.open("GET", url, true); httpObject.send(null); } else { alert ("Browser does not support HTTP Request") return } } // Change the value of the outputText field function populateJobMenu(){ if(httpObject.readyState == 4){ alert(httpObject.responseText) var combo = document.getElementById('jobfiltermenu'); combo.options.length = 0; var response = httpObject.responseText; var items = response.split(";"); var count = items.length; for (var i=0;i<count;i++){ var options = items[i].split("|"); combo.options[i] = new Option(options[0],options[1]); //alert("writing menu item"); } } } // Populate the tape list placeholder with the data returned function populateTapeList(){ if(httpObject.readyState == 4){ alert(httpObject.responseText) var combo = document.getElementById('tapelistplaceholder'); var response = httpObject.responseText; combo.innerHTML = response; } } Quote Link to comment Share on other sites More sharing options...
pingu Posted May 14, 2008 Author Share Posted May 14, 2008 Fixed it! in clientfilterAction(), I was calling httpObject.open with asynchronous set to true, change this to false: - httpObject.open("GET", url, true); and all works perfectly as expected! 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.