PDF Editing Issues

How to Create a JavaScript Tax Calculation for PDF Form Radio Buttons

Olivia MillerOlivia Miller Nov 5, 2026 871 views

Question details

The user needs to implement a custom JavaScript calculation in a PDF form to compute tax based on selected radio button options.

Create a JavaScript Tax Calculation for PDF Form Radio Buttons
Product
PDF
Device & OS
not provided
Scenario
Building an interactive PDF invoice or order form that requires conditional tax calculations, such as standard tax, tax-exempt, or a custom manual tax input.
Observed behavior
The user wants to dynamically calculate 5% tax, 0 tax, or allow manual entry in a specific Tax field depending on the active radio button selection.
Before you start

Ensure your PDF form fields are correctly named before adding the script. Specifically, verify the base amount field is named 'Total' and your radio button group is named 'TaxType'.

Solution 1Recommended

Add a Custom JavaScript Calculation to the Tax Field

Use a custom calculation script in the Tax field's properties to evaluate the selected radio button and apply the corresponding tax formula or allow manual input.

This solution utilizes standard Acrobat JavaScript. It relies on a switch statement to check the export value of the selected radio button. By default, it locks the field for automatic calculation, but unlocks it if the manual entry option is selected.

1
Configure Radio Button Export Values

Open your document in PDF form preparation mode. Double-click the 'TaxType' radio buttons to open their Properties. Under the Options tab, ensure their Export Values are set to 'Choice1' (for 5%), 'Choice2' (for zero), and 'Choice3' (for manual entry).

2
Open Tax Field Properties

Right-click the 'Tax' text field where the result will appear, select 'Properties', and navigate to the 'Calculate' tab.

3
Enter the Custom Script

Select the 'Custom calculation script' option and click 'Edit'. Paste the following JavaScript code: var nTotal = Number(this.getField("Total").value); var nChoice = this.getField("TaxType").value; event.target.readonly = true; switch (nChoice) { case "Choice1": event.value = 0.05 * nTotal; break; case "Choice2": event.value = 0; break; case "Choice3": event.rc = false; event.target.readonly = false; break; default: event.value = ""; break; }

4
Save and Test the Form

Click 'OK' to close the JavaScript editor, then close the Properties dialog. Exit form editing mode and click the radio buttons to ensure the tax calculates correctly based on the 'Total' field.

Add a Custom JavaScript Calculation to the Tax Field
Manual Entry Capability: The script intelligently sets 'event.target.readonly = false' for Choice3, which removes the read-only restriction and allows users to manually type a custom tax amount.
Advanced PDF Form Editor

Easily Manage and Edit Interactive PDF Forms with WPS Office

WPS Office provides a comprehensive PDF editor that lets you view, fill, and manage interactive PDF forms with ease. It perfectly processes standard form fields and calculations without complex configurations.

  1. 1. Open the PDF File: Launch WPS Office and open your interactive PDF form.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access robust form filling and editing tools.
  3. 3. Fill and Calculate: Input your data into the form fields. WPS PDF will automatically process embedded JavaScript calculations to display accurate results.
Seamlessly edit and fill interactive PDF forms containing complex calculations.Fully compatible with standard PDF formats and forms created in Adobe Acrobat.Lightweight, fast, and user-friendly interface for professional PDF management.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my PDF JavaScript calculation updating automatically?

The field calculation order might be incorrect. Ensure that the 'Total' field is calculated before the 'Tax' field. You can adjust this by going to the form editing mode, selecting 'More', and choosing 'Set Field Calculation Order'.

Can I change the tax rate from 5% to a different percentage?

Yes, locate the line 'event.value = 0.05 * nTotal;' in the script and change '0.05' to your desired decimal rate (for example, use '0.08' for an 8% tax rate).

How do I group radio buttons together correctly for this script?

All radio buttons in a specific group must share the exact same Name (e.g., 'TaxType' in the General tab), but each button must have a unique 'Radio Button Choice' or 'Export Value' under the Options tab.

Why can't I type manually when Choice3 is selected?

If manual entry fails, ensure that the Tax field does not have the 'Read Only' box permanently checked in its General properties tab. The script controls the read-only state dynamically, but a permanent setting may override it.