title: jQuery Stop submitting form by checking error variable
body: <p>I have a simple form with some form fields. Some of them are required some are not. The required field are required by adding the class 'required'.</p>
  
  <p>When I submit I check the <code>#contact-form</code> fields and on the basis of there I give the empty field error classes and submit the form yes or no.</p>
  
  <p>Adding the error classes to the fields is not a problem, but checking the "error" variable is. Because I don't know where I can check the error variable.</p>
  
  <p>This is my jQuery code:</p>
  
  <pre><code>$('#contact-form').submit(function (event) {
      var errors = false;
      $(this).find('.required').each(function () {
          if ($(this).val().length &lt; 1) {
              $(this).addClass('error');
              errors = true;
          }
      });
      if (errors == true) {
          event.preventDefault();
      }
  });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/6Hpe9/1/" rel="nofollow">JsFiddle</a></p>