title: How to keep checking form updates Javascript
body: <p>In my form, I have these elements [day][month][year] which enables user to enter </p>
  
  <pre><code>&lt;form id="mail" action="form.php" method="post" onsubmit="validateForm()"&gt;
      &lt;label for="dateOfBirth"&gt;Date of Birth&lt;/label&gt;
       &lt;input type="number" id="day" name="day" max="31" placeholder="Day" &gt;
       &lt;input type="number" id="month" name="month" placeholder="Month" max="12" &gt;
       &lt;input type="number" id="year" name="year" placeholder="Year" max="2016"/&gt;
      &lt;input type="submit" value="submit"&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>When the submit button is pressed, it should check if user is over 18 or not. If he is over 18, the form should submit. If the user is not over 18, it should display an error. The code to validate age is working, the only thing is that I am not sure how should I place my code</p>
  
  <pre><code>   var day = getElementById("day").value;
     var month = getElementById("day").value;
     var year = getElementById("day").value;
     var age = 18;
     var mydate = new Date();
     mydate.setFullYear(year, month-1, day);
  
     var currdate = new Date();
     var setDate = new Date();         
     setDate.setFullYear(mydate.getFullYear() + age, month-1, day);
  
     function validateForm() {
  
      if ((currdate - setDate) &gt; 0){
  
  
          preventDefault();                               // Prevent it being sent
          var details = $('#mail').serialize();         // Serialize form data
          $.post('form.php', details, function(data) {  // Use $.post() to send it
          $('#mail').html(data);                    // Where to display result
      });
  
          alert("above 18");
      }else{
  
          alert("below 18");
          $("form").submit(function(e){
              alert('submit intercepted');
              e.preventDefault(e);
          });
      }
  }
  </code></pre>
  
  <p>Code to check age <a href="http://jsfiddle.net/Ttsa8/5/" rel="nofollow noreferrer">http://jsfiddle.net/Ttsa8/5/</a></p>