Change in Javascript to work in add row

Avatar

Avatar
Validate 10
Level 2
aka44356106
Level 2

Likes

10 likes

Total Posts

56 posts

Correct reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 2
aka44356106
Level 2

Likes

10 likes

Total Posts

56 posts

Correct reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
aka44356106
Level 2

29-11-2018

I have a dynamic pdf form in which a table cell1 is Enter DOB and aother Cell2 Calculate age by Javascript calculation.

When applicant is more than one then addrow by click Button and a new row add but in new cell age calculation cell2 is show old result.

Please help me to modify this javascript so that it will work add row button.

java script (helped by  BR001)

const _MS_PER_DAY = 1000 * 60 * 60 * 24;

const _DAYS_TO_MONTH = 4800 / 146097; // 400 years have 146097 days and 400 years have 4800 months

const _MONTH_TO_DAYS = 146097 / 4800;

var date = util.scand("yyyy-mm-dd", Table8.Row1.Cell2.rawValue);

var now = new Date();

var days = Math.ceil((now - date) / _MS_PER_DAY);

var monthsFromDays = Math.floor(days * _DAYS_TO_MONTH);

var months = monthsFromDays;

days -= Math.ceil(monthsFromDays * _MONTH_TO_DAYS);

var years = Math.floor(months / 12);

months %= 12;

var result = [];

if (years > 1)

     result.push(years + " years");

if (years == 1)

     result.push(years + " year");

if (months > 1)

     result.push(months + " months");

if (months == 1)

     result.push(months + " month");

if (days > 1)

     result.push(days + " days");

if (days == 1)

     result.push(days + " day");

this.rawValue = result.join(", ");

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

01-12-2018

Hi,

I think you need to change "Table8.Row1.Cell2.rawValue" to just "Cell2.rawValue", this should make the reference relative to the table cell the calculation is in the bit "Table8.Row1" will always reference the first row as though you had used "Table8.Row1[0]"

Regards

Bruce

Answers (0)