title: Return true/false value of a javascript function and then do stuff based on that
body: <p>I'm building a contact form and I need help with the jQuery validator.</p>
  
  <pre><code>function contactform() {
      $("form #submit").on("click", function() {
          $("form input").removeClass("error");
          validator();
          // 3rd action goes here
      });
  });
  </code></pre>
  
  <p><code>validator()</code> checks to see if any input is left empty, and if so it adds an error class to it:</p>
  
  <pre><code>function validator() {
      $("form input").each(function() {
          var value = $(this).val();
          if (value.length &lt;= 0) {
              $(this).addClass("error");
              return false;
          }
      });
  });
  </code></pre>
  
  <p>Now, for the 3rd action in <code>contactform()</code> I want to say that if <code>validator() = true</code> (i.e. there no inputs that are empty), then continue on to the next code.</p>
  
  <p>I can't seem to return the value of <code>validator()</code>. Does anybody know the best way to do this?</p>