Skip to main content
Participant
April 19, 2024
Question

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

  • April 19, 2024
  • 2 replies
  • 1165 views

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

                                                     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); 

 

 

 

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
April 20, 2024

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

Participant
April 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); 

try67
Community Expert
Community Expert
April 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.

Participant
April 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!

Bernd Alheit
Community Expert
Community Expert
April 20, 2024

What scripts do you use at validation?