title: jQuery Form Validation Plugin : Return false on error
body: <p>After going through a tutorial on how make jQuery plugins, I decided to give it a shot and make a form validation plugin. I've so far managed to achieve 90% of what I was hoping for and the only thing remaining is making the form to return false if there are empty fields found.</p>
  
  <p><a href="http://jsfiddle.net/tHMMj/8/" rel="nofollow"><strong>JSFIDDLE</strong></a></p>
  
  <p>I've put my whole code at jsfiddle, but it doesn't seem to be working. Perhaps because I need to include my plugin file instead of pasting it in the script section. But I'm sharing it just in case you need to look at the whole code.</p>
  
  <h3>PLUGIN WORKFLOW</h3>
  
  <pre><code>(function(jQuery) {
      window.cnt = 0;
  
      jQuery.fn.border = function() {
  
         this.each(function() {
          var ele = jQuery(this);
          var cur_val, ele_name;
          if(// element is input, select, or textarea)
          {
             cur_val = ele.val();
          }
          else if(// element is radio)
          {
             ele_name = ele.attr('name');
             cur_val = $('input:radio[name="'+ele_name+'"]:checked').val();
          }
          else if(// element is checkbox)
          {
             ele_name = ele.attr('name');
            cur_val = $('input:checkbox[name="'+ele_name+'"]:checked').val();
          }
  
          if(! cur_val) // need to do something here to prevent form submission
          {
              cnt++;
              if(// input, textarea, select element)
              {
                 ele.addClass('border');
              }
              else if(// radio or checkbox element)
              {
                 ele.parent().addClass('border');
              }               
          }
          else // need to do something here to make the form submission happen
          {               
              if(// input, select, textarea)
              {
                  ele.removeClass('border');
              }
              else if(radio or checkbox)
              {
                  ele.parent().removeClass('border');
              }
          }
  
          });         
          return this;            
      };
  })(jQuery);// JavaScript Document
  </code></pre>
  
  <h3>WHAT I TRIED</h3>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function(){
          $('form').submit(function(){
              $('.required').border();
              if(window.cnt &gt; 0)
              {               
                  return false;
              }
              else
              {               
                  return true;
              }
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>I created a global variable <code>cnt</code> and tried using it inside the form submission function. It worked when there were empty elements, but it returned <code>false</code> even after all elements where filled up. After alerting the value of <code>cnt</code>, I found out that on each button click the value of <code>cnt</code> kept appending from its previous values and so <code>cnt &gt; 0</code> always returned <code>true</code>.</p>
  
  <p>Thus, I'm trying to find a way to return <code>false</code> from within the plugin function itself so that I won't have to add the <code>if-else</code> condition after calling the plugin function.</p>
  
  <p>In a nutshell what I'm trying to achieve is</p>
  
  <pre><code>$(function(){
      $('form').submit(function(){
          $('.required').border(); // this line should take care of returning true or false for the submit function           
      });
  });
  </code></pre>
  
  <p>Thus, the user should just call <code>$('.required').border();</code> and it should take care of the rest.</p>