Using the onblur event:
function ajaxFunction(obj)
{
var button = document.getElementById("submit");
button.disabled = true;
button.setAttribute("class", "test");
var getdate = new Date();
xmlhttp.onreadystatechange = handleServerResponse(obj);
if(xmlhttp)
{
xmlhttp.open("POST","register_ajax.php",true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(obj.name +"="+ obj.value);
};
}
Revised handleServerResponse function:
function handleServerResponse(obj)
{
alert(xmlhttp.responseText);
if (xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
obj.value=xmlhttp.responseText;
}
else
{
alert("Error during AJAX call. Please try again");
}
}
}