• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Create a formula for two fields that do not block ...

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

Community Beginner ,
Apr 19, 2024 Apr 19, 2024

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

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

209

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
6 Replies 6
Community Expert ,
Apr 19, 2024 Apr 19, 2024

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.

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

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!

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

Copied

What scripts do you use at validation?

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

Copied

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

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

Copied

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

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

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