PDF Editing Issues

How to Create an Acrobat JavaScript Formula for Optional Sales Tax Calculation

Ayan MasoodAyan Masood Nov 3, 2026 869 views

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'.

Acrobat JavaScript Formula for Optional Sales Tax Calculation
Product
PDF
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

Right-click the field where you want the tax to appear (for example, Amount7) and select 'Properties' from the context menu.

2
Access Custom Calculation Script

Navigate to the 'Calculate' tab in the Properties window, select the 'Custom calculation script' option, and click the 'Edit' button.

3
Enter the JavaScript Code

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; }

4
Format as Currency

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.

Apply Custom JavaScript for Conditional Sales Tax
Formatting Tip: Always format your output field using the built-in Currency setting rather than trying to insert text like '$0.00' directly into the JavaScript calculation result. This ensures the output remains a valid number for any further calculations.
WPS PDF Advanced Features

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. 1. Open PDF in WPS Office: Launch WPS Office and click on 'PDF Edit' to open your document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access interactive form field tools.
  3. 3. Add Form Fields: Insert Text Fields and Drop-Down lists to construct your sales invoice or document.
  4. 4. Configure Field Properties: Double-click or right-click the target field to access its properties, where you can set formatting and interaction rules.
Supports creating interactive fillable forms with powerful editing featuresHighly compatible with Adobe Acrobat PDF and Microsoft Office formats (Word, Excel, PowerPoint)Lightweight, fast, and features an intuitive interfaceAvailable across Windows, Mac, Linux, and mobile platforms
microsoft office alternative - wps office

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.