Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
function ageCalc(birth,age_num) {
let o = $('#' + birth);
let d = nuFORM.removeFormatting(o.val(), o.attr('data-nu-format'));
var dob = new Date(d);
//calculate month difference from current date in time
var month_diff = Date.now() - dob.getTime();
//convert the calculated difference in date format
var age_dt = new Date(month_diff);
//extract year from date
var year = age_dt.getUTCFullYear();
//now calculate the age of the user
var age = Math.abs(year - 1970);
console.log('age='+age);
nuSetvalue('age_num',age);
}
I have 2 fields pa_birthdate (date field with format yyyy-mm-dd) and pa_age(input field number )
I call this func as following
Pb solved. Help no longer needed for this script which works as expected. It was a typo with nuSetvalue() instead of nuSetValue() function.
The corrected function is :
function ageCalc(birth,age_num) {
let o = $('#' + birth);
let d = nuFORM.removeFormatting(o.val(), o.attr('data-nu-format'));
var dob = new Date(d);
//calculate month difference from current date in time
var month_diff = Date.now() - dob.getTime();
//convert the calculated difference in date format
var age_dt = new Date(month_diff);
//extract year from date
var year = age_dt.getUTCFullYear();
//now calculate the age of the user
var age = Math.abs(year - 1970);
console.log('age='+age);
nuSetValue('age_num',age);
}
To be put in the setup header of the application as it is used everywhere.