Solution
function calculateAge()
{
var dob = $('#DateOfBirth').val();
dob = new Date(dob);
var today = new Date();
var age = Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));
$('#Age').val(age);
}
Explanation
dob will get the date of birth from DateOfBirth text box. It will convert it into date so to calculate further. today will store the current date. The result of math.floor function will be stored in age variable and the value of age will be displayed in the Age field.
Leave a comment