0

I have a form with many fields. When the user picks his date of birth, I want the form to automatically calculate the age based on the dob and today and report that result in the age field.
See what i implemented again:All, Thanks for your response.But I still have issue implementing that. See my code and correct :

 <p> Date of Birth:
    <input type="date" name="dob" value="" id="dob" placeholder="Date of Birth" required="required"/></p>
    <script> function agefinding()
    {
        var birthDay = document.getElementById("dob").value;
        var DOB = new Date(birthDay);
        var today = new Date();
        var age = today.getTime() - DOB.getTime();
        age = Math.floor(age / (1000 * 60 * 60 * 24 * 365.25));
       // alert(age);
        //return age;
        document.getElementById('age').value = age;
    }</script>  
      <p> Age:
    <input type="numeric" name="age" value="" id="age" placeholder="Age" required="required"/></p>
ʰᵈˑ
  • 11,279
  • 3
  • 26
  • 49
David Mukoro
  • 467
  • 1
  • 8
  • 25
  • @David I think you forgot put some code you were willing to put here. – Tariq Oct 30 '14 at 11:06
  • use datepicker. I think these two links might help u. http://stackoverflow.com/questions/4151480/getting-age-automatically-when-given-date-of-birth http://stackoverflow.com/questions/19521146/calculate-age-based-on-date-of-birth – Soorajlal K G Oct 30 '14 at 11:17
  • Check this link it may hep you http://stackoverflow.com/questions/4060004/calculate-age-in-javascript – Choco Oct 30 '14 at 11:24
  • Thank you all. I have the solution now. – David Mukoro Oct 30 '14 at 15:25

0 Answers0