title: jQuery closing pop-up after successful form submit
body: <p>I have a pop up form that i wish to close on successfull submit of the form.  Currently we are only validating on the server side which will create an unordered list of validation errors with the class .error_message.</p>
  
  <p>Once the form has been successfully submitted i want to close the window.</p>
  
  <p>Currently the jQuery i am using for this is as follows but does not work because the first time the form has been submitted the number of error messages will always be zero.</p>
  
  <pre><code>$(document).ready(function() {
  
  $('form#emailQuote').submit(function() {
  
      var $emailErrors = $('form#emailQuote ul.error_message').length;
  
      alert($emailErrors);
  
      if ($emailErrors == 0) {
          //window.close();
          alert('no errors');
  
      } else {
          //alert('errors');
          alert('errors');
      }      
  });
  </code></pre>
  
  <p>});</p>