Other PDF Issues

How to Calculate Conditional Shipping Costs with JavaScript in Adobe PDF Forms

John WilsonJohn Wilson Nov 10, 2026 869 views

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.

How to Calculate Conditional Shipping Costs with JavaScript in PDF Forms
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Prepare Form Mode

Open your document in Adobe Acrobat, navigate to the 'Tools' menu, and select 'Prepare Form' to enable form editing.

2
Access Field Properties

Right-click the 'Total Before Tax' field (or whichever field represents your pre-tax total) and select 'Properties' from the context menu.

3
Enable Custom Calculation

Go to the 'Calculate' tab in the Properties window, select the 'Custom calculation script' radio button, and click the 'Edit' button.

4
Enter the JavaScript Code

Paste the following script into the editor: if (event.value < 55) { this.getField("ShippingCost").value = 10; } else { this.getField("ShippingCost").value = 0; }

5
Save and Test

Click 'OK' to save the script, close the Properties window, and switch to 'Preview' mode to test entering different total values.

Add a Custom Calculation Script to the Pre-Tax Field
Match Your Field Names: JavaScript is case-sensitive. If your shipping field is named something other than 'ShippingCost', you must update the this.getField("YourFieldName") portion of the script to match it exactly.
Powerful PDF Form Editor

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. 1. Open Your Form: Launch WPS Office and open your interactive PDF form.
  2. 2. Fill the Fields: Click directly into the text fields, checkboxes, or dropdowns to fill out the form naturally.
  3. 3. Sign and Save: Use the PDF tools to insert an electronic signature if needed, then easily save or share the completed document.
Seamless compatibility with standard Adobe PDF forms.Easy-to-use tools for filling, signing, and managing PDF documents.Cost-effective and lightweight alternative to heavy PDF software.Cross-platform support for Windows, Mac, iOS, and Android.
QA img-9

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.