jQuery newbie here. As you can see the codes bellow, I'm trying to pass a value after such event, basically returning the date and age to hidden fields.
// Compute age (fld_age) according DOB fields
$('#fld_birth_yy, #fld_birth_mm, #fld_birth_dd').on('change', function(e){
e.preventDefault();
if ($('#fld_birth_yy').val() != 0 && $('#fld_birth_mm').val() != 0 && $('#fld_birth_dd').val() != 0) {
var str_dob = $('#fld_birth_yy').val() + '/' + $('#fld_birth_mm').val() + '/' + $('#fld_birth_dd').val();
$('input[name="fld_dob"]').val(str_dob);
$('input[name="fld_age"]').val(calcAge(str_dob));
console.log(calcAge(str_dob));
}
});
function calcAge(dateString) {
var birthday = +new Date(dateString);
return~~ ((Date.now() - birthday) / (31557600000));
}
Please point-out what I'm missing...