title: jquery Datepicker date range validation
body: <p>I have a field like Born date. I have used jquery datepicker to show the calender so that user can select the date.Now I have a problem.</p>
  
  <p>In the the Born date field there is a option to choose between which opens two date picker fields like</p>
  
  <p>Born Date -- Between--------- ---From------- And --To----------</p>
  
  <p>Now the problem is if the user selects a date in 'To field' which is less than 'From field' and press the submit button it gets submitted. I need to prevent it from submitting and display appropriate message so the user enters right date .</p>
  
  <p>Please Help.</p>
  
  <p>Here is the code that i am using</p>
  
  <pre><code>&lt;input id="borndate"  class="dateISO" onchange="checkDate('borndate');"&gt;
  &lt;/input&gt;
  
  &lt;span id="span_borndate" style="display:none"&gt;
  &lt;input  id="borndate"  class="dateISO"  onchange="checkDate('borndate');"&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>This is the Java script i am using</p>
  
  <pre><code>function checkdate(fieldname) {
  
      var comparator = '#comp_' + fieldName;
      var compVal = $(comparator).val();
      Value = $('#' + fieldName).val();
      var fromDate = jQuery.datepicker.parseDate('mm-dd-yy', Value, null);
      Values = $('#' + fieldName + '-to').val();
      var toDate = jQuery.datepicker.parseDate('mm-dd-yy', Values, null);
      $('#span_' + fieldName).find('.error').remove();
      if (compVal == "Between") {
          if (toDate &lt; fromDate) {
              $('#span_' + fieldName).append("&lt;label class='rangeError' generated='false'&gt;Start date should come before end date&lt;/label&gt;");
              return false;
          }
      }
      return true;
  }
  </code></pre>
  
  <p>And this is the function which is called again while submitting</p>
  
  <pre><code>function validateforms() {
      var valid = true;
      $('//classnamefor table rows which includes the date td').each(function (index) {
          fieldName = $(this).attr("name");
          if ($('#' + fieldName).hasClass('dateISO')) {
              valid = checkDate(fieldName);
          }
      }
      return valid;
  }
  </code></pre>