How to Calculate Conditional Shipping Costs with JavaScript in Adobe PDF Forms
Question details
The user wants to set up a conditional JavaScript calculation in a PDF form to automatically adjust the shipping cost based on the pre-tax total.

- Product
- Adobe Acrobat PDF Forms
- Device & OS
- not provided
- Scenario
- Creating a fillable PDF order form where shipping is a flat rate (€10) for orders under €55, and free (€0) for orders of €55 or more.
- Observed behavior
- Requires a custom JavaScript calculation script that dynamically updates the ShippingCost field depending on the value entered in the Total Before Tax field.
Ensure you are using a PDF editor with form authoring and JavaScript support, and confirm the exact field names for your pre-tax total and shipping cost fields before adding the script.
Add a Custom Calculation Script to the Pre-Tax Field
Trigger the shipping cost update by embedding a JavaScript snippet directly into the calculation properties of the 'Total Before Tax' field.
This method executes the script every time the pre-tax total is modified, instantly updating the shipping cost to either 10 or 0 based on your threshold.
Open your document in Adobe Acrobat, navigate to the 'Tools' menu, and select 'Prepare Form' to enable form editing.
Right-click the 'Total Before Tax' field (or whichever field represents your pre-tax total) and select 'Properties' from the context menu.
Go to the 'Calculate' tab in the Properties window, select the 'Custom calculation script' radio button, and click the 'Edit' button.
Paste the following script into the editor: if (event.value < 55) { this.getField("ShippingCost").value = 10; } else { this.getField("ShippingCost").value = 0; }
Click 'OK' to save the script, close the Properties window, and switch to 'Preview' mode to test entering different total values.

Edit and Manage PDF Forms Easily with WPS Office
If you need a reliable and lightweight tool to fill, edit, and manage standard PDF forms, WPS Office provides a comprehensive PDF editor perfectly compatible with interactive forms.
- 1. Open Your Form: Launch WPS Office and open your interactive PDF form.
- 2. Fill the Fields: Click directly into the text fields, checkboxes, or dropdowns to fill out the form naturally.
- 3. Sign and Save: Use the PDF tools to insert an electronic signature if needed, then easily save or share the completed document.

Frequently Asked Questions
Why isn't my JavaScript calculation working in the PDF?
The most common reason is mismatched field names. Ensure that the field name referenced in your script (e.g., "ShippingCost") exactly matches the actual name of the shipping field in your form's properties. Also, check for typographical errors, as JavaScript is fully case-sensitive.
Can I place the calculation script in the Shipping Cost field instead?
Yes. If you prefer to place the script in the 'ShippingCost' field itself, open its properties, go to the Calculate tab, and use this script: var total = this.getField("Total Before Tax").value; if (total < 55) { event.value = 10; } else { event.value = 0; }
How do I format the shipping cost to display as a currency?
To format the output, open the 'Properties' of your 'ShippingCost' field, navigate to the 'Format' tab, select 'Number' from the category dropdown, and then choose your preferred currency symbol and decimal places.
Will this JavaScript work if someone opens the PDF in a web browser?
Not always. While standard desktop PDF readers like Adobe Acrobat fully support PDF JavaScript, many built-in web browser PDF viewers (like Chrome or Edge) have limited or no support for JavaScript calculations. For best results, advise users to fill out the form in a dedicated PDF application.




