• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

TOPICS
Acrobat SDK and JavaScript

Views

301

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
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 17, 2018 Aug 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;

Votes

Translate

Translate
Community Expert ,
Aug 17, 2018 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;

Votes

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
community guidelines
LEGEND ,
Aug 17, 2018 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.

Votes

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
community guidelines
Community Expert ,
Aug 18, 2018 Aug 18, 2018

Copy link to clipboard

Copied

LATEST

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;

Votes

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
community guidelines
New Here ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

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

Votes

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
community guidelines