Hi,

I am using JavaScript to retrieve information from a XML source file.

I have written a getXML() function to "return" the xml document.

In development the function worked fine, untill I removed my alert function that I was using to help me build the function.

It seems the function now tries to return the xmlDocument variable before it is set by the previous statement: "xmlDocument = XMLHttpRequestObject.responseXML;"

How can I make the function wait untill the variable is set before it tries to return it's value?

Code:
function getXML(dataSource)	{
	if(XMLHttpRequestObject)	{
		var xmlDocument;
		XMLHttpRequestObject.open("GET",dataSource);
		
		XMLHttpRequestObject.onreadystatechange = function()	{
			if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)	{
				xmlDocument = XMLHttpRequestObject.responseXML;
				//This is where my alert function used to be
				return xmlDocument;
			}
		}
		
		XMLHttpRequestObject.send(null);
	}
}
I have also tried returning the XMLHttpRequestObject.responseXML; directly as well as placing the return at the end of the function with no success.

Any help would be appreciated.

Thank you