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

Create a formula for two fields that do not block each out

Community Beginner ,
Apr 19, 2024 Apr 19, 2024

Seeking help on creating two formulas that do not cancel each other. I can create a formula for each of the two fields, separately, but they no longer work when both formulas are in place. These are the two formulas I am currently working with. After entering the current rate, I would like the option of either entering the percentage to calculate the new rate OR after adding the new rate it calculates the percentage.

                                           Current                                New

Nicholas368583879o54_0-1713555006726.png

                                                     Increase

First formula is to show the percentage between the current and new pay rates:

var a = Number(this.getField("New").valueAsString);
var b = Number(this.getField("Current").valueAsString);
if(b)
event.value = ((a-b)/b)*1;
else
event.value = "";

 

Second formula is to calculate the new pay rate based on current rate and increase percentage:

var b = this.getField("Current").value;

var c = this.getField("Increase").value;

var newPayRate = currentPayRate * (1 + increasePercentage / 100); event.value = newPayRate.toFixed(2); 

 

 

 

TOPICS
Create PDFs , How to , JavaScript , PDF forms
814
Translate
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 ,
Apr 19, 2024 Apr 19, 2024

Instead of a calculation script you need to use the Validation event of each field to populate the other one. That why they won't overwrite each other and the user would be able to fill either one.

Translate
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 Beginner ,
Apr 19, 2024 Apr 19, 2024

Unfortunately, that did not work. I moved the formulas for each field from calculation script to validation script. I got out of edit mode and tested out the fields, I input the current rate then new rate and the percentage did not show. Same with the other, I input the current rate and added a percentage and the new rate did not populate. Could it be the formula I am using or version of acrobat (Adobe Acrobat 9 Standard)? I appreciate your help with this!

Translate
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 ,
Apr 19, 2024 Apr 19, 2024

What scripts do you use at validation?

Translate
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 Beginner ,
Apr 20, 2024 Apr 20, 2024
LATEST

I used the following in the validation event for each field.

 

For the "Increase" percentage field I used this formula to show the percentage between the current and new pay rates:

var a = Number(this.getField("New").valueAsString);
var b = Number(this.getField("Current").valueAsString);
if(b)
event.value = ((a-b)/b)*1;
else
event.value = "";

 

For the "New" rate field I used this formula to calculate the new pay rate based on current rate and increase percentage:

var b = this.getField("Current").value;

var c = this.getField("Increase").value;

var newPayRate = b * (1 + c / 100); event.value = newPayRate.toFixed(2); 

Translate
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 ,
Apr 19, 2024 Apr 19, 2024

In the second script, where did you declare variables 'currentPayRate' and 'increasePercentage'?

Translate
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 Beginner ,
Apr 20, 2024 Apr 20, 2024

That was a mistake on my end. Should be current or increase OR b=Current and c=Increase

 

Second formula is to calculate the new pay rate based on current rate and increase percentage:

var b = this.getField("Current").value;

var c = this.getField("Increase").value;

var newPayRate = b * (1 + c / 100); event.value = newPayRate.toFixed(2); 

Translate
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