Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
What scripts do you use at validation?
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
In the second script, where did you declare variables 'currentPayRate' and 'increasePercentage'?
Copy link to clipboard
Copied
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);