May 11, 2021 at 8:10 pm #6187
I’m trying to subtract two fields. I have no idea how to do it
I’ve attached what i’m working onMay 11, 2021 at 8:18 pm #6382
Even Acrobat itself doesn’t offer a simple way to do subtractions. Not quite sure why, but probably because x – y (and x / y) is not the same as y – x and y / x (as opposed to addition and multiplication, which are commutable).
So a custom calculation script is needed to handle this.
The basic idea is as I mention in this thread: http://id-extras.com/forum/viewtopic.php?id=53
In your case, we would need to modify it a little, like this:
To get the value of a field, use this command:Code:this.getField(“Field1”).value
To update the value of the selected field, use:Code:event.value = …
So putting it all together, try the following as your custom calculation script:Code:event.value = this.getField(“Field1”).value – this.getField(“Field2”).value
Does that work?
ArielMay 11, 2021 at 8:36 pm #6383
no. I have to be doing something wrong.
by selecting the field for “Profit $” (see my screenshot)
i put in a custom script under calculate>custom calculation script:
event.value = this.getField(“Field45”).value – this.getField(“Field50”).value
brought it into adobe and used Edit>FormMaker and it did not fill the field correctlyMay 11, 2021 at 8:40 pm #6384
Can you post the PDF here (or send it to me privately) AFTER running FormMaker on it in Acrobat?May 11, 2021 at 8:46 pm #6385
here you goMay 11, 2021 at 8:47 pm #6386
By the way, looking at your screenshot, I hope you are aware of the “calculation order” issue. In your form, it is important that some fields are calculated first, and other fields later, and the final field last of all. Being aware of this in advance will save hassle later on.
With FormMaker, a number at the end of the name of a form field (which is set in InDesign’s Buttons and Forms panel) decides the calculation order for the field. The higher the number, the later the field is calculated.
For instance, if one field is called “Text Field 3” and another is called “Text Field 10”, and both have calculation scripts attached to them, the calculation script attached to Text Field 3 will be run before that of Text Field 10.
More details here: https://www.id-extras.com/help/formmaker-help/May 11, 2021 at 8:52 pm #6387
Thanks for posting the form.
Ok, so it’s a simple mistake, easy to make.
Your script is:Code:event.value = this.getField(“Field45”).value – this.getField(“Field75”).value
But the names of the fields in question are actually “Text Field 45” and “Text Field 75”, respectively. So the script should look like this:Code:event.value = this.getField(“Text Field 45”).value – this.getField(“Text Field 75”).valueMay 11, 2021 at 9:02 pm #6388