How to Create an Acrobat JavaScript Formula for Optional Sales Tax Calculation
Question details
The user needs to create a custom calculation script in a PDF form that selectively applies a 6% sales tax only when a drop-down field is set to 'Yes', and returns zero when it is set to 'No'.

- Product
- Device & OS
- not provided
- Scenario
- Calculating conditional sales tax in an interactive, fillable PDF form.
- Observed behavior
- The goal is to automatically calculate a 6% tax on combined fields if 'Yes' is selected, and output exactly 0 if 'No' is selected, properly formatted as currency.
Ensure you have your PDF form open in an editor that supports custom JavaScript calculations. Verify the exact, case-sensitive names for your drop-down and amount fields before implementing the script.
Apply Custom JavaScript for Conditional Sales Tax
Use a custom calculation script in the target field's properties to evaluate the drop-down choice and calculate the tax dynamically.
This script retrieves the values of your specified amount fields and the drop-down field. It checks if the drop-down export value is set to 'No' and returns 0. If set to 'Yes' (or anything else), it calculates a 6% tax on the combined amount.
Right-click the field where you want the tax to appear (for example, Amount7) and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab in the Properties window, select the 'Custom calculation script' option, and click the 'Edit' button.
Enter the following script, replacing field names like 'Amount3', 'Amount4', and 'Dropdown' to match your form exactly: var amount3 = Number(this.getField("Amount3").value) || 0; var amount4 = Number(this.getField("Amount4").value) || 0; var taxable = this.getField("Dropdown").value; if (taxable == "No") { event.value = 0; } else { event.value = (amount3 + amount4) * 0.06; }
Switch to the 'Format' tab in the Properties window. Select 'Number' or 'Special' category and set it to display as a currency, which automatically handles the dollar sign formatting.

Create and Edit Fillable PDFs Easily with WPS Office
WPS Office includes a robust PDF editor that allows you to design interactive, fillable PDF forms with text fields, drop-down menus, and advanced properties.
- 1. Open PDF in WPS Office: Launch WPS Office and click on 'PDF Edit' to open your document.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access interactive form field tools.
- 3. Add Form Fields: Insert Text Fields and Drop-Down lists to construct your sales invoice or document.
- 4. Configure Field Properties: Double-click or right-click the target field to access its properties, where you can set formatting and interaction rules.

Frequently Asked Questions
Why is my PDF JavaScript calculation returning an error or not updating?
This usually happens if the field names in your script do not exactly match the field names in the PDF form (they are case-sensitive), or if the calculation order in your PDF form settings is incorrect.
How do I ensure the drop-down value triggers the script properly?
Check the 'Options' tab of your drop-down field properties. Ensure the 'Export Value' is explicitly set to exactly what your script expects (e.g., 'Yes' or 'No') and check the box for 'Commit selected value immediately'.
Can I change the tax rate in the formula later?
Yes. You can edit the custom calculation script at any time. Simply change the multiplier in the script (for example, replace 0.06 with 0.08 for an 8% tax rate).
Should I include the currency symbol inside the JavaScript code?
No. It is highly recommended to output a plain number from your JavaScript calculation and use the built-in Field Properties under the 'Format' tab to display the field as Currency.




