title: how to automatically populate the age field after entering dob filed in jsp.?
body: <p>My jsp code is as follows:(A simple registartion from with fields)</p>
  
  <pre><code> &lt;label&gt;DOB&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="dob" /&gt; &lt;/td&gt;&lt;/tr&gt;
   &lt;tr&gt;&lt;td&gt;
   &lt;label&gt;AGE&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="age" onclick =" ageCount()"/&gt; &lt;/td&gt;&lt;/tr&gt;
   &lt;tr&gt;&lt;td&gt;
   &lt;label&gt;GENDER&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="radio" name="gender" value="Male"/&gt;Male&lt;input    
    type="radio" name="gender" value="Female"&gt;Female&lt;/td&gt;&lt;/tr&gt;
   &lt;tr&gt;&lt;td&gt;
  </code></pre>
  
  <p>I used a function in JS to calculate the age from dob! Dob is in sql Date format.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function ageCount(){
  var date1 = new date();
  var dob = document.getElementById("dob").value;
  var date2 = new date(dob);
  var pattern = /^\d{1,2}\/\d{1,2}\/\d{4}$/; 
  if(pattern.test(dob)){
      var y1 = date1.getFullYear();
      var y2 = date2.getFullYear();
      var age = y1-y2;
      document.write("Age :" +age);
      return true;
  }else{
      alert("invalid date fromat.!! Please enter in (DD/MM/YYYY) format");
      return false;
  }
       }
  
  
       &lt;/script&gt;
  </code></pre>
  
  <p>how do i use this so that when i enter the dob and press tab the age should be displayed in its field.
  Drop in your ideas and suggestions.</p>