Set an If-Then-Else Calculation for Invoice Fields in Adobe Acrobat
Question details
Set an invoice PDF field to 50 when the product of two other fields is greater than 1 and less than 50, and leave it blank when the first field is blank or zero.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- An invoice form uses fields A and B as inputs and field C as a calculated output.
- Observed behavior
- Field C should show 50 only for products strictly between 1 and 50 and should not retain an old value when the condition is not met.
Open the invoice in Adobe Acrobat and confirm that the form fields are named A, B, and C. You need access to Acrobat's form-editing and custom calculation script tools.
Add a custom calculation script to field C
Use this script to calculate the product and clear field C whenever the specified condition is not met.
Open the invoice PDF in Acrobat and select All tools > Prepare a form. Check the field names in the form editor.
Double-click field C, select the Calculate tab, choose Custom calculation script, and click Edit.
Paste this script into the JavaScript editor and confirm it: var a = Number(this.getField("A").value); var b = Number(this.getField("B").value); var product = a * b; if (a !== 0 && isFinite(a) && isFinite(b) && product > 1 && product < 50) { event.value = 50; } else { event.value = ""; }
Close the field properties, preview the form, and enter values in A and B. Test a product between 1 and 50, the boundary values 1 and 50, and a blank or zero value in A.

Work with invoice documents in WPS Office
WPS Office is a free, lightweight alternative for working with office documents and PDFs. Its familiar interface and Microsoft Office format compatibility make it easy to move existing invoice files. Acrobat custom calculation scripts should still be configured and tested in Acrobat.

Frequently Asked Questions
Where do I put the calculation script in Acrobat?
Select All tools > Prepare a form, double-click field C, and open Calculate > Custom calculation script > Edit.
Will field C show 50 when the product is exactly 1 or 50?
No. The conditions product > 1 and product < 50 exclude both boundary values.
Why does the script include an else branch?
The else branch assigns an empty string to event.value when the condition is not met, preventing field C from retaining a previous result.
What if my form fields have different names?
In the script, replace "A" and "B" in the getField calls with the exact names shown in Acrobat's form editor. Place the script in the output field's calculation settings.




