title: "Waiting" for ReadyState to be 4 before returning a value
body: <p>I have looked in lots of places for this, and I'm probably being an idiot because this is done a lot, but here's my situation.</p>
  
  <p>I am trying to display a checkbox next to an e-mail field on my website iff the e-mail has not been used to register already.</p>
  
  <p>What I have is something like this:</p>
  
  <pre><code>$('[name=reg_email]').change( function() { 
      if(!emailUsed()) {
          //Update image to be a green checkmark
      } else {
          //Update image to be a huge red X
      }
  }
  </code></pre>
  
  <p>And my "emailUsed" function should be returning a Javascript boolean variable depending on whether or not the e-mail address is in the database. To facilitate this, I've created a script which will determine if it's there or not. So the emailUsed() function just needs to call the script and return, but I need to wait until readystate == 4 before I return, and all of the methods I have found for waiting for readystate to equal 4 prevent me from returning a value at all:</p>
  
  <pre><code>function emailUsed() {
      var req = $.get('scripts/email_used.php?email='+$('[name=reg_email]').val());
  
      //Wait for req.readystate to be 4
  
      return req.responseText == 'True';
  }
  </code></pre>
  
  <p>But nowhere can I find something that explains how to do this and still return a value. Everything seems to use callback functions and this and that, but I can't get THIS method to return a value.</p>
  
  <p>Help, please!</p>