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

Monthly/Annually Fields update based on eachother's value

New Here ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

Hello! 

 

I am trying to make it so Monthly/Annually both update based on the value that is entered or updated.

Is it possible to get each of these 2 fields to update once either is filled in or when the value of either is changed? 

It seems i can get one field to calculate based on the other but not vice versa .

 

HolliyWell_0-1595023858701.png

event.value = Number(this.getField("txt_Annually").value) / 12;      in Monthly field

event.value = Number(this.getField("txt_Monthly").value) * 12;      in Annually field

I currently have these 2 calculations in each respective field. At the moment it doesnt allow you to alter the value inside the Monthly field.

 

Any advice would be greatly appreciated!

 

TOPICS
Acrobat SDK and JavaScript

Views

359

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 , Jul 17, 2020 Jul 17, 2020

You can try it like this:

 

//Place this code as custom calculation script of Monthly field

if (event.source && event.source.name =="txt_Annually") {event.value = Number(this.getField("txt_Annually").value/12);}
else event.value = event.target.value;


//and place this code as custom calc script of the Annually field

if (event.source && event.source.name =="txt_Monthly") {event.value = Number(this.getField("txt_Monthly").value*12);}
else event.value = event.target.value;

 

Note: Credit to Try67 wh

...

Votes

Translate

Translate
Community Expert ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

You can try it like this:

 

//Place this code as custom calculation script of Monthly field

if (event.source && event.source.name =="txt_Annually") {event.value = Number(this.getField("txt_Annually").value/12);}
else event.value = event.target.value;


//and place this code as custom calc script of the Annually field

if (event.source && event.source.name =="txt_Monthly") {event.value = Number(this.getField("txt_Monthly").value*12);}
else event.value = event.target.value;

 

Note: Credit to Try67 who coached me on how to apply (event.source && event.source.name)  a while ago.

 

This will allow both fields to calculate based on each other's values and remain editable.

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 ,
Jul 18, 2020 Jul 18, 2020

Copy link to clipboard

Copied

Thank you! Thought it might be something like this.

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 ,
Jul 18, 2020 Jul 18, 2020

Copy link to clipboard

Copied

LATEST

You're welcome.

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