// holds an instance of XMLHttpRequest var xmlHttp = createXmlHttpRequestObject(); // holds the remote server address var valid_script = server + "validateajax.php"; // when set to true, display detailed error messages var showErrors = true; // initialize the validation requests cache var cache = new Array(); // creates an XMLHttpRequest instance function createXmlHttpRequestObject() { // will store the reference to the XMLHttpRequest object var xmlHttp; // this should work for all browsers except IE6 and older try { // try to create XMLHttpRequest object xmlHttp = new XMLHttpRequest(); } catch(e) { // assume IE6 or older var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"); // try every id until one works for (var i=0; i= 0 || response.indexOf("error:") >= 0 || response.length == 0) throw(response.length == 0 ? "Server error." : response); // get response in XML format (assume the response is valid XML) responseXml = xmlHttp.responseXML; // get the document element xmlDoc = responseXml.documentElement; result = xmlDoc.getElementsByTagName("result")[0].firstChild.data; fieldID = xmlDoc.getElementsByTagName("fieldid")[0].firstChild.data; // find the HTML element that displays the error message = document.getElementById(fieldID); // show the error or hide the error message.className = (result == "0") ? "error" : "hidden"; // call validate() again, in case there are values left in the cache setTimeout("validate();", 500); } // sets focus on the first field of the form function setFocus() { document.getElementById("txtUsername").focus(); }