How to Calculate Pennsylvania and Philadelphia Sales Tax in PDF Forms
Question details
The user needs an Acrobat JavaScript script to accurately calculate sales tax based on the specific rates for Pennsylvania and Philadelphia.

- 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.
Ensure your PDF form contains properly configured and exactly named text fields for 'State', 'City2', and 'Subtotal' before applying the calculation script.
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.
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'.
In the Field Properties dialog box, click on the 'Calculate' tab and choose the 'Custom calculation script' option.
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;
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.

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. Download WPS Office: Get the free WPS Office suite from the official website and install it on your computer or mobile device.
- 2. Open Your PDF: Launch WPS PDF and open your interactive PDF form.
- 3. Interact and Save: Easily input data into the form fields, review the document, and save your completed PDF directly.

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.




