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.]
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;
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;
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.
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;
Copy link to clipboard
Copied
That worked perfectly. THANK YOU. You are a rock star.