Jump to content

Populate two elements from one drop down.


pingu

Recommended Posts

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;
}

}

 

 

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.