title: Ajax wont let me return true or false
body: <p>I am trying to return true for the entire validator.registercallback function if the following ajax script doesn't return 1.  However, it isn't working, and I think its probably something basic that I'm missing, but I can't figure it out.</p>
  
  <pre><code>validator.registerCallback('unique_username', function(value) {
  
          //use ajax to run the check  
          var xmlhttp;
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
        if(xmlhttp.responseText != 1) {
            alert('Username Exists');
            return false;
        } else {
            alert('Username Available!');
            return true;
        }
      }
    }
  xmlhttp.open("GET","uniqueuser.php?username="+value,true);
  xmlhttp.send();
  
  })
  </code></pre>
  
  <p>What's weird is that the following works, it just doesn't work based on the value of the ajax script:</p>
  
  <pre><code>validator.registerCallback('unique_username', function(value) {
  
          //use ajax to run the check  
          var xmlhttp;
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
        if(xmlhttp.responseText != 1) {
            alert('Username Exists');
            return false;
        } else {
            alert('Username Available!');
            return true;
        }
      }
    }
  xmlhttp.open("GET","uniqueuser.php?username="+value,true);
  xmlhttp.send();
  
  return true;
  
  })
  </code></pre>
  
  <p>So basically, I can tell it to return true in the main function, but when I try to make it return true ONLY IF the value in the ajax script doesn't return 1, it doesn't work.  By the way, the alerts DO WORK.  So it IS getting the right value, but it wont return true, or false for that matter.</p>
  
  <p>Any help is appreciated!</p>
  
  <p><em>Update</em></p>
  
  <pre><code>validator.registerCallback('unique_username', function(value) {
  
          //use ajax to run the check  
  function ajax_result() {
    var xmlhttp;
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
      }
    }
  xmlhttp.open("GET","uniqueuser.php?username="+value,true);
  xmlhttp.send();
  }
  
  if(ajax_result() != 1) { 
  
  alert('Username Exists');
  return false;
  
  } else {
  
  alert('Username Available!');
  return true;
  
  }
  
  })
  </code></pre>