How to Create a PDF Form Markup Calculation Script by Price Range
Question details
The user needs a custom calculation script for a PDF form to dynamically assign a markup multiplier based on a provided price range.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Setting up a dynamic PDF document for quoting or invoicing where a specific markup multiplier changes according to the numerical value entered into the 'Price' field.
- Observed behavior
- The goal is to automatically output a markup value of 1.10, 1.20, or 1.30 depending on whether the input price is <=5, between 5 and 7, or between 7 and 10.
Ensure you have a PDF editor that supports JavaScript form logic (like Adobe Acrobat Pro) and verify that a text field named exactly 'Price' already exists in your document.
Adding a Custom JavaScript Calculation for Markup Ranges
Use the custom calculation script feature in your PDF editor to implement conditional logic that reads the 'Price' field and outputs the corresponding markup multiplier.
Advanced PDF forms utilize JavaScript to handle complex conditional logic. By extracting the value of the 'Price' field, you can set up an if-else statement to determine the correct markup and assign it directly to the markup field.
Open your PDF in 'Prepare Form' mode. Right-click the specific text field where you want the markup to appear (e.g., the 'Markup' field) and select 'Properties'.
In the Text Field Properties dialog box, click on the 'Calculate' tab to set up your mathematical logic.
Select the 'Custom calculation script' radio button and click 'Edit'. Paste the following code: var price = Number(this.getField("Price").valueAsString); if (price <= 5) event.value = 1.1; else if (price <= 7) event.value = 1.2; else if (price <= 10) event.value = 1.3;
Click 'OK' to close the script editor, then close the Properties window. Enter different numerical values into your 'Price' field to verify that the markup field updates automatically.
Manage and Fill Interactive PDF Forms with WPS Office
WPS Office offers a comprehensive PDF editor that allows you to easily view, manage, and fill interactive PDF forms, ensuring accurate calculations and a smooth document workflow.
- 1. Open the PDF: Launch WPS Office and click on the 'PDF' tab to open your interactive document.
- 2. Fill the Form Fields: Click into the form fields. WPS PDF will automatically recognize interactive text boxes, including those with built-in calculation scripts.
- 3. Save or Export: Once the calculations are complete and the form is filled out, click 'Save' or export the document directly to your device.

Frequently Asked Questions
Why is my PDF form calculation script not updating automatically?
The calculation order might be incorrect, or the field triggering the calculation isn't set to commit the selected value immediately. Check your form properties under 'Options' and ensure 'Commit selected value immediately' is checked on the input field.
Can I use standard math operators instead of JavaScript in PDF forms?
Yes, for simple mathematical operations like addition, multiplication, or averaging, you can select 'Value is the [sum/product] of the following fields' directly in the Calculate tab without needing to write custom JavaScript.
How do I prevent the script from showing a default value when the Price field is empty?
You can wrap your script in a check that verifies if the field is empty before calculating. For example, add 'if (this.getField("Price").valueAsString === "") { event.value = ""; return; }' at the beginning of your calculation script.




