I figured it out. The script IS getting ahead of itself, so to speak. I guess Javascript just keeps going after the AJAX call. What I did was create a new function that checked the value of 'returnVals' and set a timeout on that function of 500. That way, the AJAX has time to get the response into the returnVals variable so when it gets checked, it knows what to do. Here's the resulting code:
function ajax()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
function returnAjax(getVars)
{
xmlHttp = ajax();
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById('returnVals').value = xmlHttp.responseText;
}
}
strURL = "process.php?" + getVars;
xmlHttp.open("GET",strURL,true);
xmlHttp.send(null);
}
function checkSN(strSN,strDis)
{
returnAjax('action='+strDis+'&strSN='+strSN)
setTimeout('checkSNReturn()',500);
}
function checkSNReturn()
{
if(document.getElementById('hidVals').value == 'true')
{
alert("Serial number already exists in Bound Book!");
}
document.getElementById('hidVals').innerHTML = '';
}