Hey all,

I am trying to use a javascript function to run an sql query via an external php page and then use the returned value of that to then execute more javascript before executing another mysql script via an external php.

Basically I want it to do this ->

Code:
function()
{
    Send value through to php with xmlhttp
    return variable1

    if(variable1 == true)
    {
         run some more javascript stuff
    }

    send off another xmlhttp using variable1 as well as some other stuff passed into the function

}
I'm not sure if this makes sense but I am having trouble because (I think) the second xmlhttp doesn't wait for the first one to return variable1 so when it fires variable1 is undefined.. I also tried the approach of having the first xmlhttp in a seperate function and calling that but it seemed to have the same problem.

Any help would be much appreciated!

ps this is the code I am using:

Code:
    if(window.XMLHttpRequest)
    {
	xmlhttp = new XMLHttpRequest();
     }
    else
    {
	xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    }
				
    xmlhttp.onreadystatechange = function()
    {
	if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
	{
	    variable1= xmlhttp.responseText;					
	}
    }
				
    xmlhttp.open("GET", "../phpurl.php?variable1="+variable1, true);
    xmlhttp.send();