Skip to main content
Participant
March 31, 2024
Frage

Subtracting 3 form fields without continuing to minus their result when inputting other form field

  • March 31, 2024
  • 1 Antwort
  • 711 Ansichten

Hello, please help me.

Is there a custom calculation script for this to happen? I have 3 fields to be subtracted from the first form field and when I input other form filled they keep subtracting from each other (only the 3 form filled)

this is my calculation script:

 

var a = this.getField("3").value;

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

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

event.value = a;

if (a !=="" && b !=="") {event.value = a - b;}

if (a !=="" && c !=="") {event.value = a - c;} ;

;

 

 

So the final result of their difference would be on Field 3.

Please tell me where I went wrong on this one. I also tried setting their calculation order it just keeps messing up. Or is there a custom script for this to prevent from subtracting furthermore.

 

Thank you! I use adobe acrobat

Dieses Thema wurde für Antworten geschlossen.

1 Antwort

Thom Parker
Community Expert
Community Expert
March 31, 2024

Calculation scripts are run every time any field on the form changes. Using the value of the field in a calculation script on that field creates a feedback loop, not good.  To fix this issue you need to add another form field to hold the field "3" value and break the loop. 

 

BTW: using numbers as field names is a bad practice. Use short descriptive names. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
March 31, 2024

Thank you for your response.

 

So what you mean is , there is no way that I can calculate 2 fields to result on the first? That's why it creates a loop? 

Participant
March 31, 2024

The calculation chain needs to follow a forward only progression. 

So add a text field to recieve the result of the first calculation, call it Result1.

so Result1 = Box1 - Box2

Then add a text field to recieve the result from the second calculation, call it Result2.

So Result2 = Result1 - Box3

 

Put the calculation scripts into the Result1 and Result2 text fields. Now there is now feedback.

 

 


Thank you for this wonferful information.

I have another problem,

when I enter other data from the other form fields they somehow keep subtracting still from Box2 and Box3, is there any way to just minus them once?