Skip to main content
Participant
January 8, 2024
Question

Every field entry, including non-calculated fields, causes a recalculation

  • January 8, 2024
  • 1 reply
  • 530 views

I am creating a 2-page fillable form. The 2nd page has calculations on each line. All except Machine Cost are using the product (x) of two fields. For Machine Cost, I have the below in the Custom calculation script:

 

var nResult=0;
var nA = 0;
var nB = 0;

//Acquire inputs
var nA = Number(this.getField("ListPrice1").valueAsString);

var nB = Number(this.getField("Discount1").valueAsString);


//Test if discount is 0 and perform calculation

if (nB == 0){
nResult = nA;
} else {
nResult = nA - (nA * (nB/100));
}

//Assign Result to Field

event.value = nResult;

 

Every time I enter anything into any field on the form, it is forcing a recalculation. There is a lag/delay and it looks like a calculator icon.

 

How can I prevent this from happening?

 

I am using Adobe Acrobat Pro Version 2023.008.20458

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
January 8, 2024

This is how PDF files work. To prevent it from happening you would need to set up a complex system that looks at which field triggered the calculation event and only perform those calculations that are dependent on that field.

But this really should not be necessary unless you have a very complex form with a lot (hundreds) of calculated fields. If that's not the case with your file the lag is most likely caused by an incorrect setup of the calculations.

Thom Parker
Community Expert
Community Expert
January 8, 2024

I agree with Try67. The form must have either loads of calculations or the calculations are retriggering themselves. 

Examine the calculation order to be sure it is correct, and make sure the results of later calculations are not feeding eariler calculations. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often