var intUserNameMinSize = 5; var intUserNameMaxSize = 20; var elemUserName, elemUserNameStatus; function checkUserNameStatus(){ if(!elemUserName){ elemUserName = document.getElementById('userName'); } if(!elemUserNameStatus){ elemUserNameStatus = document.getElementById('userNameStatus'); } var len = elemUserName.value.length; if(lenintUserNameMaxSize){ elemUserNameStatus.innerHTML = " too long"; return; } doAjaxRequestUsernameAvailable('/gateway/username_available.php?userName=' + elemUserName.value, 'GET', true, updateUserNameStatus); } var signup_xmlhttp; function updateUserNameStatus(){ //callback for the ajax request if (signup_xmlhttp.readyState == 4) { elemUserNameStatus.innerHTML = signup_xmlhttp.responseText; } } //just keeping things standalone function doAjaxRequestUsernameAvailable(strURL,strGETorPOST,bAsync,callbackFunction){ //makes an ajax request //if callbackFunction is provided, the request will be asynchronus //else the call is sync and we return the html result if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari signup_xmlhttp=new XMLHttpRequest(); }else{ // code for IE6, IE5 signup_xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); } if(strGETorPOST=='GET'){ signup_xmlhttp.open('GET',strURL,bAsync); if(bAsync) signup_xmlhttp.onreadystatechange = callbackFunction; signup_xmlhttp.send(); }else if(strGETorPOST=='POST'){ var i = strURL.indexOf('?'); var strParams = ''; if(i!=-1){ strParams = strURL.substr(i+1); strURL = strURL.substr(0,i); } signup_xmlhttp.open('POST',strURL,bAsync); if(bAsync) signup_xmlhttp.onreadystatechange = callbackFunction; signup_xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); signup_xmlhttp.setRequestHeader("Content-length", strParams.length); signup_xmlhttp.setRequestHeader("Connection", "close"); signup_xmlhttp.send(strParams); }else{ alert('Invalid usage - must provide GET or POST'); } if(bAsync) return; var html; if(signup_xmlhttp.status==200){ html = signup_xmlhttp.responseText; }else{ html = 'HTTP Status ' + signup_xmlhttp.status + ' from ' + strURL ; } return(html); }