Skip to main content
Azzarrel
Participant
February 19, 2017
Answered

How to properly use calculations in forms?

  • February 19, 2017
  • 1 reply
  • 570 views

So i just downloaded the test version of Acrobat DC, because i wanted to try a few things with Forms and the posibility to wirte own calculations with JavaScript for example.

My problem is, that I don't know where to start. There are a few guides and tutorials, but they go waaay too deep for my issue, so i thought i might ask here.

I'd like to execute some simple calcuations in my pdf like:

I have 3 fields. One is the total value and the other 2 are parts of the total vauel. (e.g. field 1 has a vaule of 1000 and field 2 has a vaule of 600, so field 3 has one of 400. Lowering the vaule of field 2 from 600 to 550 increases the value of field 3 by 50)

I have on field with a drop down menue (so lets stick to my first issue and lets say that i have a dozen fields of different values and split values, but only 3-4 matter in a time), so I'd like to make the first field with the total value a drop down field with all different total vaules witle field 2 and 3 change automatically based on the current total value in field 1.

There are quite a few simular examples, but i guess if i know how to solve these 2, i can figure out how to solve to rest on my own.

My problem right now is, that while I am quite comfortable with java, i didn't use java scrypt that much, neither did i use Acrobat DC until now.

Can anyone provide me with a proper tutoral for my specific problem?

This topic has been closed for replies.
Correct answer try67

Have you seen this tutorial: https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations ? It covers quite a lot of what you've discussed here.

Basically your request is very simple. You just want to set "field 3" to be equal to "field 1" - "field 2".

To do that you can use this code as the custom calculation script of "field 3":

event.value = Number(this.getField("field 1").value) - Number(this.getField("field 2").value);

It doesn't matter for the purposes of the calculation if "field 1" is a text field or a drop-down, as long as it only has numeric values.
Try it out and you'll see...

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 19, 2017

Have you seen this tutorial: https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations ? It covers quite a lot of what you've discussed here.

Basically your request is very simple. You just want to set "field 3" to be equal to "field 1" - "field 2".

To do that you can use this code as the custom calculation script of "field 3":

event.value = Number(this.getField("field 1").value) - Number(this.getField("field 2").value);

It doesn't matter for the purposes of the calculation if "field 1" is a text field or a drop-down, as long as it only has numeric values.
Try it out and you'll see...