How to Make Sales Tax Optional with a Checkbox in PDF Forms
Question details
The user needs to add a conditional checkbox to a PDF receipt form that includes or excludes a specific sales tax rate from the grand total when toggled.

- Product
- PDF Form Editors
- Device & OS
- not provided
- Scenario
- Creating a dynamic PDF receipt form with conditional tax calculations based on user selection.
- Observed behavior
- The user wants a conditional script where selecting or deselecting a checkbox recalculates the grand total dynamically.
Ensure you know the exact field names for your 'Subtotal' field and your 'AddTax' checkbox, as JavaScript calculations in PDF forms are strictly case-sensitive.
Use a Custom Calculation Script in the Grand Total Field
Apply a JavaScript snippet to the Grand Total field to conditionally calculate the tax based on the checkbox state.
Instead of applying a script to the checkbox itself, the calculation should be handled directly by the Grand Total field. This ensures the total updates dynamically whenever the form fields are modified or the checkbox is toggled.
Right-click the Grand Total field in your PDF form editor and select 'Properties'.
In the Properties dialog box, click on the 'Calculate' tab to view calculation options.
Select 'Custom calculation script' and click 'Edit'. Enter the following JavaScript code: var taxRate = 0.0725; var subtotal = Number(this.getField('Subtotal').valueAsString); var addTax = this.getField('AddTax').valueAsString; if (addTax == 'Off') event.value = subtotal; else event.value = subtotal * (1 + taxRate);
Ensure that 'Subtotal' and 'AddTax' in the script perfectly match the actual names of your form fields.

Create and Edit Interactive PDF Forms with WPS Office
WPS PDF provides robust tools for viewing, filling, and managing interactive PDF forms. Whether you need to handle invoices, receipts, or complex dynamic documents, WPS Office offers a powerful and accessible experience.
- 1. Open your PDF Form: Launch WPS Office and open your PDF receipt or interactive form document.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to highlight and view all interactive fields.
- 3. Fill and Save: Interact with checkboxes, fill in text fields, and save your completed document effortlessly.

Frequently Asked Questions
Why is my grand total not updating when I click the checkbox?
This typically happens if the field calculation order in the PDF is incorrect, or if the field names in your JavaScript snippet do not exactly match the actual form field names (which are case-sensitive).
Can I use a different tax rate in the custom script?
Yes, simply modify the `var taxRate = 0.0725;` line in the script to reflect your local tax rate. For example, for a 5% tax, change it to `var taxRate = 0.05;`.
Does the checkbox field itself need a calculation script?
No, the checkbox does not need its own script. The logic is entirely managed within the Grand Total field's custom calculation script, which checks the status of the checkbox to determine the final value.




