title: Calculate age from "Date" HTML element
body: <p>I have an HTML form with "Date" element and a submit button. There are 2 functions. One is for calculating age from given birth date in the "date" HTML element. The other function is for comparing the age with minimal allowed age. I need help to complete it. See my questions in remarks in code. Yes, I have seen other similar questions. I would like to learn and not just copy/paste. If I understand what is wrong with my code / syntax, then I will learn better. Thanks in advance.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0  Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
     &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
   &lt;script type="text/javascript"&gt;
  
      var minAge = 18;
  
      var curDate = new Date();
  
      var curr_year = curDate.getFullYear();
      var curr_month = curDate.getMonth();
  
  
      //Calculates age from given Birth Date in the form//
      function _calcAge() {
  
          var dt1 = document.getElementById('date').value;
          var birth_date = new Date(dt1);
  
          var birth_year = birth_date.getFullYear();
          var birth_month = birth_date.getMonth();
          var calc_year = curr_year - birth_year;
          var calc_month = curr_month - birth_month;
  
          //The following below is what I am not sure about. 
          //I need to combine years and months and
          //convert them into a string??? Is this syntax dead wrong?
  
      var final_result = (calc_year &amp;&amp; "." &amp;&amp; calc_month).toString();
  
          // final result should be a number with a decimal point, example: 35.5
          final_result = parseFloat;
  
          return (final_result);
          alert(final_result);
      }
  
      //Compares calculated age with minimum age and acts according to rules//
      function _setAge() {
  
          var age = _calcAge();
          //alert("my age is " + age);
          if (age &lt; minAge) {
              alert("You are not allowed into the site. The minimum age is 18!");
          } else
  
              alert("Welcome to my Site");
              window.open(main.htm, _self);
  
      }
  
  
      &lt;/script&gt;
  
       &lt;form&gt;
        Date Of Birth: &lt;input type="date" name="date of birth" id="date" /&gt;
        &lt;input type="submit" name="submit" id="submit" onClick="_setAge();" /&gt;
  
       &lt;/form&gt;
  
      &lt;/body&gt;
     &lt;/html&gt;
  </code></pre>