Copy link to clipboard
Copied
Copy link to clipboard
Copied
I answered you in another post, you can't use that in custom calculation script, use the same under simplified field notation or use this in custom calculation script:
var a = Number(this.getField("TOTALONE").valueAsString);
var b = Number(this.getField("TOTALTWO").valueAsString);
var c = Number(this.getField("TOTALTHREE").valueAsString);
var d = Number(this.getField("LESSADVANCES").valueAsString);
event.value = a+b+c-d;
Copy link to clipboard
Copied
So, does the a+b=c+d equal the GrandTotal
Copy link to clipboard
Copied
This is your form. You are the one who decides how the calculation works. Nesa was just guessing about the names of the fields on your form based on the labels used on the form. You asked about adding 3 numbers and subtracting one number. That is exactly the code that was provided.
In the context of scripting. "a+b=c+d" makes no sense. I'm not sure what you are trying to do with it. Go with the code Nesa provided, but change the field names to match the fields on the form.
If you'd like to learn about writing calculation script in Acrobat, see these links:
https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm
https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm
Copy link to clipboard
Copied
Thank you....I'm still learning.
Copy link to clipboard
Copied
Thank you. I don't know what I'm doing wrong, but still cannot get the calculation to give a total in the GrandTotal field. I changed the a+b+c-d to match my field names.
Copy link to clipboard
Copied
Thank you for your help...but I still do get a total in the GRAND TOTAL field.
Can you help me with that? Do I need a calculate button? Which I have no idea on how to creat.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Here's the correct calculation script
var a = Number(this.getField("TotalOne").valueAsString);
var b = Number(this.getField("TotalTwo").valueAsString);
var c = Number(this.getField("TotalThree").valueAsString);
var d = Number(this.getField("LESSADVANCES").valueAsString);
event.value = a+b+c-d;
Field Names must be verbatim, including the case. And the last line, which is the calculation, uses the variables defined above it.
Copy link to clipboard
Copied
Hello @Tori36186819mjz7 ,
It's important to understand that Adobe Acrobat uses a JavaScript core interpreter to perform various systematic actions and arithmetic calculations.
As @Nesa Nurani and @Thom Parker pointed out, like any programming language, particularly Acrobat JavaScript, all arithmetic formulas you create must adhere to specific expressions and Acrobat JavaScript rules to achieve the intended outcome.
I think you were specifically talking about using a Simplified Field Notation (SFN), which is distinct from the solutions that have already been shared since your original post mentions JavaScript. It creates a bit of confusion for us trying to understand your requirement.
In this context, writing a simplified field notation requires a different syntax than that of a Custom Calculation Script. Additionally, in your shared PDF you disregarded the advice that @try67 and @PDF Automation Station already shared with you in your intial post: https://community.adobe.com/t5/acrobat-discussions/simple-multiplication-of-two-fields/td-p/15516016
The names of the fields that you will refer to in your scripts need to be spelled precisely as you wrote them when you created them. Currently, you spelled all of the field names in your SFN in Upper Case, but your fields are spelled Case Sensitive. I've noticed in your shared document that you also have the same error in other total fields.
Note that, with the exception of the field "LESSADVANCES", your SFN syntax should be expressed exaclty as :
TotalOne + TotalTwo + TotalThree - LESSADVANCES
Additionally, because SFN mostly resembles arithmetic expressions (rather than JavaSript scripting expressions), if you are employing SFN expressions, you should get in the habit of expressing arithmetic formulas like so:
(TotalOne + TotalTwo + TotalThree) - LESSADVANCES
Employing parenthesis ( ) in arithmetic formulas greatly helps someone to visually grasp the execution order of an equation if they would be reviewing your work; it just makes it a lot easier to understand in a human-readable form what needs to happen first in an equation.
Also, you've used the Custom Calculation Script to declare the value of "GrandTotal" using the SFN syntax in it.
Should you decide to keep your work entirely as SFN, move the expresion of TotalOne + TotalTwo + TotalThree - LESSADVANCES to the Simplified Field Notation item under the Claculate tab (like you've done before). Otherwise, you may copy and paste the scripts provided by @Nesa Nurani and @Thom Parker and use them to test your results as Custom Calcution Scripts (not SFN); both methods should trigger the same result values.
Here is an updated PDF from your original work with some improvements: Travel-Expense-2025
Copy link to clipboard
Copied
Thanks for your advice. I'm still learning!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now