title: stopping form submit if the validation fails.
body: <p>I am validating the dates in below function. If the validation fails, then the form should not get submitted. I tried returning false in form onsubmit but it still gets submitted. However, Validation is working fine and getting the alert that  I put in the function. Any help to stop submitting the form if validation fails. </p>
  
  <pre><code>&lt;script&gt;
    function dateCheck()
    {
        start = document.getElementById('name3').value;
        end = document.getElementById('name4').value;
        compare(start, end);
        document.getElementById('name4').focus();
  
    }
  
    function compare(sDate, eDate)
    {
  
        function parseDate(input) {
              var parts = input.match(/(\d+)/g);
  
              return new Date(parts[2], parts[0]-1, parts[1]); // months are 0-based
            }
         var parse_sDate = parseDate(sDate);
        var parse_eDate = parseDate(eDate);
         parse_sDate.setFullYear(parse_sDate.getFullYear() + 1);
  
        if(parse_eDate &gt;= parse_sDate)
            {
            alert("End date should not be greater than one year from start date");
             return false;
            }
         return true;
    }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form onsubmit="return dateCheck()"&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;input type="text" name="soname3" id="name3" size="15" readonly="readonly"&gt; 
  &lt;img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /&gt;&lt;/td&gt;
   &lt;td&gt;&lt;input type="text" name="soname4" id="name4" size="15" readonly="readonly"&gt;
   &lt;img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12'); " /&gt; &lt;/td&gt;
   &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>