Skip to main content
Participant
August 17, 2018
Answered

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.

  • August 17, 2018
  • 2 replies
  • 463 views

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.]

This topic has been closed for replies.
Correct answer try67

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;

2 replies

Participant
August 17, 2018

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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 17, 2018

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;

Inspiring
August 17, 2018

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.

try67
Community Expert
Community Expert
August 18, 2018

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;