title: jQuery Validate: compare two fields
body: <p>I want to check if value entered in one field is less than value entered in other field.</p>
  
  <p>The Html:</p>
  
  <pre><code>&lt;form id="bid_form_id"&gt;
      &lt;input type="text" name="bid_price" id="bid_price_id" value=""&gt;
      &lt;input type="text" name="bid_auto_decrement" id="bid_auto_decrement_id" value=""&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>&lt;script&gt;
  
      jQuery(document).ready(function ($) {
  
          $.validator.addMethod('le', function (value, element, param) {
              return this.optional(element) || value &lt;= $(param).val();
          }, 'Invalid value');
  
  
          $('#bid_form_id').validate({
              errorElement: "small",
              rules: {
                  bid_price:
                          {
                              required: true,
                              number: true
  
                          },
                  bid_auto_decrement:
                          {
                              required: true,
                              number: true,
                              le: '#bid_price_id'
                          }
              },
              messages: {
                  bid_auto_derement: {le: 'Must be less than bid price.'}
              }
  
          });
      });
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>The 'bid_auto_decrement' value should be less than the 'bid_price' value.
  The script works for the first time. If I enter larger value in 2nd field, it shows 'invalid value' but after that if I enter correct values, it still shows error.</p>