title: Username check prior to form submission - JQUERY/AJAX
body: <p>I have been using this example: <a href="http://youhack.me/2010/05/04/username-availability-check-in-registration-form-using-jqueryphp/" rel="nofollow">http://youhack.me/2010/05/04/username-availability-check-in-registration-form-using-jqueryphp/</a> to create a form (takes user to confirmation page before adding to database - easy part which comes after)..however i would like it to check whether a username is available or not prior to submitting the form. I cannot for the life of me figure out what im doing wrong with it :P</p>
  
  <p>MY jquery/AJAX is below: (the PHP file it calls works fine i have no need to put it on here)</p>
  
  <pre><code>$(document).ready(function()
      {
          $(".form").submit(function()
          { 
              var username = $(".userID").val();
  
              $.ajax({  
                  type: "POST",
                  url: "id_check.php",  
                  data: "userID="+ username,  
                  success: function(response){
  
                      if(response=="NO"){
                          alert("no");    
                      }
                      else if(response=="YES"){   
                          alert("yes");
                      }
                  }
  
              });
  
              return false; //if i take this line out it submits either way
  
          });
  
      });
  </code></pre>
  
  <p>I know the php works because the correct alert pops up when a username is taken or not, but i cannot get it to submit the form when the response is YES without it submitting when the response is also NO. I have tried many different things (including $(form).submit() and various returns etc within the IF statements) but to no avail. </p>
  
  <p>I basically need it to submit when the name is not taken and to NOT submit when it is...any help is greatly appreciated!! (i think ive included all information necessary to potentially fix it haha)</p>
  
  <p>Alan</p>