I would like to calculate the age of the user as soon as he selects a date from jquery datepicker.
$(document).ready(function() {
$( "#nominee_one_dob" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
onSelect: function (date) {
var dob = Date.parse(date);
if (dob.addYears(18) < Date.today())
{
alert("Under 18");
}
else
{
alert(" Over 18");
}
}
});
I am able to get the date selected when i alert(date)
but I am not getting anything from the further code.
Please help.