PDF Editing Issues

How to Add a Conditional Shipping Fee JavaScript Formula in Acrobat PDF

Maira MehtabMaira Mehtab Nov 3, 2026 869 views

Question details

The user wants to automatically calculate a shipping fee in a PDF form using JavaScript, specifically charging a $10 fee for orders under $100 and providing free delivery for orders of $100 or more.

How to Add a Conditional Shipping Fee JavaScript Formula in Acrobat PDF
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an interactive PDF order form that automatically adds delivery charges based on the subtotal.
Observed behavior
The user requires a specific conditional calculation script to assign a $10 fee or $0 fee dynamically based on the 'Total Price' field's value.
Before you start

Ensure you are using the full version of Adobe Acrobat (Standard or Pro) to create and edit form fields, as free PDF readers generally only allow you to fill out existing forms without script editing capabilities.

Solution 1Recommended

Use Custom Calculation Script for the Delivery Fee Field

Add a JavaScript ternary operator to the delivery fee field properties to conditionally apply the $10 charge based on the total price.

This method uses Acrobat's built-in JavaScript capabilities. The script will read the value of your 'Total Price' field, evaluate whether the amount meets the $100 threshold for free shipping, and instantly output the correct delivery fee.

1
Enter Prepare Form Mode

Open your PDF document in Adobe Acrobat, go to the 'Tools' menu, and select 'Prepare Form' to enable field editing.

2
Open Field Properties

Right-click on your designated 'Delivery Fee' text field and select 'Properties' from the context menu.

3
Navigate to the Calculate Tab

In the Text Field Properties dialog box, click on the 'Calculate' tab to access the calculation options.

4
Add the Custom Script

Select 'Custom calculation script' and click the 'Edit' button. Paste the following code: var total = Number(this.getField("Total Price").valueAsString); event.value = total < 100 ? 10 : 0;

5
Save and Test

Click 'OK', then click 'Close'. Preview your form and enter different amounts in the 'Total Price' field to ensure the delivery fee adjusts to $10 or $0 automatically.

Use Custom Calculation Script for the Delivery Fee Field
Exact Field Naming Required: The JavaScript code specifically calls for a field named 'Total Price'. If your subtotal field is named differently, you must update the script to match your exact field name.
Manage PDF Forms Effortlessly

Edit and Fill PDF Forms with WPS Office

WPS Office includes a versatile PDF editor that allows you to easily view, fill out, and manage interactive PDF forms. It is a highly compatible and lightweight solution for all your document needs.

  1. 1. Open WPS Office: Launch the WPS Office application and click on 'PDF' to open your existing PDF form document.
  2. 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to access interactive form filling and editing tools.
  3. 3. Interact with Fields: Click directly into the text fields, checkboxes, or dropdowns to input your data or trigger built-in calculations.
  4. 4. Save Your Form: Once you have completed the form, click on the 'Menu' button and select 'Save As' to secure your finalized document.
Easily interact with and fill out standard PDF formsModify PDF text, images, and pages with an intuitive interfaceHigh compatibility with standard Adobe PDF document formatsLightweight application that uses minimal system resources
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF JavaScript calculation not updating automatically?

If your conditional script isn't triggering, check your Acrobat preferences. Go to Edit > Preferences > Forms and ensure 'Automatically calculate field values' is checked. Additionally, verify that your form's calculation order evaluates the 'Total Price' field before the 'Delivery Fee' field.

Can I add multiple shipping fee tiers using JavaScript?

Yes. Instead of a ternary operator, you can use an 'if...else if' statement. For example: if (total < 50) { event.value = 15; } else if (total < 100) { event.value = 10; } else { event.value = 0; }.

Why does my delivery fee field show a syntax error after pasting the code?

Syntax errors generally occur due to missing parentheses, missing semicolons, or the use of stylized smart quotes instead of straight quotes. Ensure you have copied the code precisely and that the field name precisely matches the one used in your form.

Can I use a free PDF reader to create this calculation script?

No. While free PDF readers can execute the script when a user fills out the form, you need a full-featured PDF editing software like Adobe Acrobat Standard or Pro to initially create the form fields and inject the custom JavaScript code.