title: How to display age based on dob in html javascript
body: <p>In the code below, how do I display age based on date of birth into a text box. When I am trying outside it's working in normal. How to write onchange() based on date of birth?</p>
  
  <p>This is sample code.Can any one help me from this issue</p>
  
  <p><strong>html</strong></p>
  
  <pre><code>&lt;input type="text" name="date_birth1"   class="login-input" placeholder="Date Of Birth" id="datepicker1" autofocus&gt;
     &lt;input type="text" name="age" id="age" pattern = "^\D{0,100}$"  class="login-input" placeholder="Age" autofocus &gt;
  </code></pre>
  
  <p><strong>javascript</strong></p>
  
  <pre><code>&lt;script&gt;
  
          $(function() {
  
              $("#datepicker").datepicker({ dateFormat: "yy-mm-dd" }).val()
  
          });
          $(function() {
  
              $("#datepicker1").datepicker();
  
          });
          $(function() {
  
              $("#datepicker2").datepicker();
  
          });
          $(function() {
  
              $("#datepicker3").datepicker();
  
          });
          $(function() {
  
              $("#datepicker4").datepicker();
  
          });
          $(function() {
  
              $("#datepicker5").datepicker();
  
          });
          $(function() {
  
              $("#datepicker6").datepicker({ dateFormat: "yy-mm-dd" }).val()
  
          });
      $(function() {
          $('#datepicker1').datepicker({
  
          onSelect: function(value, ui) {
              var today = new Date(), 
                  dob = new Date(value), 
                  age = new Date(today - dob).getFullYear() - 1970;
  
              $('#age').text(age);
          },
          maxDate: '+0d',
          yearRange: '1920:2010',
          changeMonth: true,
          changeYear: true
      });
      });
          &lt;/script&gt;
  </code></pre>