PDF Editing Issues

How to Calculate Pennsylvania and Philadelphia Sales Tax in PDF Forms

Bushra ParveenBushra Parveen Nov 3, 2026 869 views

Question details

The user needs an Acrobat JavaScript script to accurately calculate sales tax based on the specific rates for Pennsylvania and Philadelphia.

How to Calculate Pennsylvania and Philadelphia Sales Tax Using Acrobat JavaScript
Product
Adobe Acrobat PDF Forms
Device & OS
not provided
Scenario
Calculating location-specific sales tax automatically within a fillable PDF form.
Observed behavior
The original script used invalid switch syntax and incorrectly checked the State field twice instead of verifying the city, resulting in incorrect tax calculations.
Before you start

Ensure your PDF form contains properly configured and exactly named text fields for 'State', 'City2', and 'Subtotal' before applying the calculation script.

Solution 1Recommended

Apply Conditional JavaScript for State and City Tax Rates

Replace the flawed switch statements with a straightforward 'if' conditional script to apply specific tax rates based on the state and city fields.

Using nested switch statements for this scenario often overcomplicates the logic and leads to errors. A simple conditional check ensures that the general Pennsylvania rate is applied by default, while the higher Philadelphia rate is correctly triggered when the city matches.

1
Access the Target Field Properties

Open your PDF form in preparation or edit mode, right-click the text field where you want the tax to be calculated, and select 'Properties'.

2
Navigate to the Calculate Tab

In the Field Properties dialog box, click on the 'Calculate' tab and choose the 'Custom calculation script' option.

3
Enter the JavaScript Code

Click the 'Edit' button and input the following script: var state = this.getField("State").value; var city = this.getField("City2").value; var rate = 0; if (state === "PA") { rate = (city === "Philadelphia") ? 0.0108 : 0.0106; } event.value = rate * this.getField("Subtotal").value;

4
Save and Test the Form

Click 'OK' to save the script, then close the properties window. Test your form by entering 'PA' in the State field, 'Philadelphia' (or another city) in the City2 field, and a number in the Subtotal field to verify the calculation.

Apply Conditional JavaScript for State and City Tax Rates
Zero Rate Handling: The script initializes the rate variable at 0, ensuring that users from Maryland, Delaware, or other states will automatically receive a zero sales tax calculation.

Manage and Fill PDF Forms Efficiently with WPS Office

Looking for a seamless way to handle PDF forms and document processing? WPS Office provides robust PDF editing capabilities alongside a comprehensive productivity suite.

  1. 1. Download WPS Office: Get the free WPS Office suite from the official website and install it on your computer or mobile device.
  2. 2. Open Your PDF: Launch WPS PDF and open your interactive PDF form.
  3. 3. Interact and Save: Easily input data into the form fields, review the document, and save your completed PDF directly.
Highly compatible with standard PDF forms and Microsoft Office file formats (Word, Excel, PowerPoint)Free, lightweight, and user-friendly interface for document managementCross-platform support allowing you to read and fill PDFs on Windows, Mac, and mobile devices
microsoft office alternative - wps office

Frequently Asked Questions

Why does the script return zero for states like Maryland or Delaware?

The script specifically initializes the 'rate' variable to 0. Since the condition 'if(state === "PA")' evaluates to false for states like Maryland or Delaware, the rate remains 0, resulting in a zero tax calculation.

How do I find the correct field names in my PDF form?

In your PDF editor's form preparation mode, right-click the field and select Properties. The exact field name will be displayed in the General tab. Ensure the names in your script perfectly match the names of your form fields.

Can I add more states to this JavaScript calculation?

Yes. You can expand the script by adding 'else if' statements to check for other state abbreviations and assign their respective tax percentages to the 'rate' variable.