I have a form with monthly and annual expense columns. I would like it if the user could fill in either with both autofilling the other while still leaving them fillable.

New Here ,
Aug 17, 2018

Copy link to clipboard

Copied

I have an Acrobat form with monthly and annual expense columns. I would like it if the user could fill in either with both autofilling the other while still leaving them fillable. So if the user puts $10 in the monthly column the annual would auto calculate to $120. But, if they change the annual column to $144 the monthly would change to $12. Is there a way to script this?

[Title shortened for clarity, and because the example got cut off... -Mod.]

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Let's say the fields are called "Monthly" and "Yearly". As the custom validation script of the "Monthly" field enter this:

if (event.value) this.getField("Yearly").value = Number(event.value)*12;

And as the custom validation script of "Yearly" enter:

if (event.value) this.getField("Monthly").value = Number(event.value)/12;

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

127

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

I have a form with monthly and annual expense columns. I would like it if the user could fill in either with both autofilling the other while still leaving them fillable.

New Here ,
Aug 17, 2018

Copy link to clipboard

Copied

I have an Acrobat form with monthly and annual expense columns. I would like it if the user could fill in either with both autofilling the other while still leaving them fillable. So if the user puts $10 in the monthly column the annual would auto calculate to $120. But, if they change the annual column to $144 the monthly would change to $12. Is there a way to script this?

[Title shortened for clarity, and because the example got cut off... -Mod.]

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Let's say the fields are called "Monthly" and "Yearly". As the custom validation script of the "Monthly" field enter this:

if (event.value) this.getField("Yearly").value = Number(event.value)*12;

And as the custom validation script of "Yearly" enter:

if (event.value) this.getField("Monthly").value = Number(event.value)/12;

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

128

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 17, 2018 0
Most Valuable Participant ,
Aug 17, 2018

Copy link to clipboard

Copied

Let's say the fields are called "Monthly" and "Yearly". As the custom validation script of the "Monthly" field enter this:

if (event.value) this.getField("Yearly").value = Number(event.value)*12;

And as the custom validation script of "Yearly" enter:

if (event.value) this.getField("Monthly").value = Number(event.value)/12;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 17, 2018 0
Adobe Community Professional ,
Aug 17, 2018

Copy link to clipboard

Copied

When I did that with Acrobat DC, it resulted in a loop where the validation script of Monthly was executed 35 times and the validation script of Yearly was executed 34 times. Not sure why it stopped there.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 17, 2018 0
try67 LATEST
Most Valuable Participant ,
Aug 18, 2018

Copy link to clipboard

Copied

You're right, it's causing a circular validation. Better to do it using the calculation event, with this code:

// For the Monthly field

if (event.source && event.source.name=="Yearly" && event.source.value!=0)

     event.value = Number(this.getField("Yearly").value)/12;

// For the Yearly field

if (event.source && event.source.name=="Monthly" && event.source.value!=0)

     event.value = Number(this.getField("Monthly").value)*12;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 18, 2018 0
New Here ,
Aug 17, 2018

Copy link to clipboard

Copied

That worked perfectly. THANK YOU. You are a rock star.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 17, 2018 0