Calculate Age from HTML input date type using getFullYear() method - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Date

Description

Calculate Age from HTML input date type using getFullYear() method

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from www.j  a  va 2s  .  co m

var today=new Date();
var dob=new Date("1/1/2000");
var age=today.getFullYear()-dob.getFullYear();
document.getElementById("age").value=age;

    }

      </script> 
   </head> 
   <body> 
      <input type="text" id="age">  
   </body>
</html>

Related Tutorials