i was using this to post name-value pairs to a php script
you can add onblur="ajaxFunction(this.id,this.value)" to your forms input fields so they can validate in real time. I had div elements with id's the same as their corrosponding form field but with an x infront (i read somewhere not to give things the same id). hope this helps anyone...
Code:
function ajaxFunction(id,value){
var ajaxRequest;//ajax var
try{// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch(e){//Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){// Something went wrong
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){//handle response
if(ajaxRequest.readyState == 4){
document.getElementById("x"+id).innerHTML = ajaxRequest.responseText;
}
}
var infoToSend = encodeURI("id="+id+"&value="+value);
ajaxRequest.open("POST", "server.php", true);
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", infoToSend.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(infoToSend);
}