PDF Editing Issues

How to Populate a PDF Field with a Discount Amount or Percentage

Camila MilosovichCamila Milosovich Nov 2, 2026 869 views

Question details

The user needs to use JavaScript in a PDF form to calculate a final discount field based on either a fixed discount amount or a percentage field, ensuring both values are not applied simultaneously.

How to Populate a PDF Field with a Discount Amount or Percentage
Product
PDF Forms
Device & OS
not provided
Scenario
Creating an interactive PDF form where a user can enter a discount either as a flat amount or a percentage, and a script calculates the correct value to populate the final output field.
Observed behavior
The form requires custom calculation logic to check which discount field is populated, assign that value to the output field, and handle cases where both fields might be empty or zero.
Before you start

Ensure your PDF editor supports advanced form field editing and custom JavaScript calculations, such as Adobe Acrobat Pro or WPS Office's advanced PDF tools.

Solution 1Recommended

Use Custom JavaScript for Field Calculation

Apply a custom JavaScript calculation script to the target field to read the input from the amount and percentage fields and determine which value to output.

To accomplish this, you need to set up a script on the output field (e.g., 'DiscountTotal') that checks the values of your two input fields (e.g., 'Amount' and 'Percentage'). The script evaluates which field is greater than zero and applies it.

1
Open PDF Form Properties

Enter the form editing mode in your PDF software. Right-click on the target field where you want the final discount to appear and select 'Properties'.

2
Navigate to the Calculate Tab

In the Text Field Properties dialog box, click on the 'Calculate' tab to set up the field's calculation logic.

3
Add Custom Calculation Script

Select the 'Custom calculation script' option and click the 'Edit' button.

4
Insert the JavaScript Code

Enter the following script, replacing 'X' and 'Y' with the actual names of your Amount and Percentage fields respectively: var n = this.getField("X").value; if (n > 0) { event.value = n; } var m = this.getField("Y").value; if (m > 0) { event.value = m; } else if (n == 0) { event.value = ""; } Click 'OK' to save.

Use Custom JavaScript for Field Calculation
Field Prioritization: In the provided script, if a user accidentally enters values in both fields, the script prioritizes field 'Y' (the percentage field in this example) because it is evaluated last. Add field validation to the input fields to prevent both from being filled simultaneously.
Advanced PDF Form Editing

Create and Manage Interactive PDF Forms with WPS Office

WPS Office provides a comprehensive suite of PDF tools, allowing you to easily create fillable forms, configure text fields, and set up interactive document layouts for your business needs.

  1. 1. Open your PDF Document: Launch WPS Office and open the PDF file you wish to turn into an interactive form.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal the interactive field creation tools.
  3. 3. Insert Text Fields: Select 'Text Field' and draw the boxes where you want users to input their discount amount or percentage.
  4. 4. Edit Field Properties: Double-click the inserted fields to rename them, adjust their appearance, and set formatting rules for numbers or percentages.
Easily insert and customize text fields, checkboxes, and dropdownsFully compatible with standard PDF form formatting and Adobe Acrobat filesLightweight application with an intuitive, user-friendly interfaceSeamlessly export and share completed forms across devices
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF form calculation not updating automatically?

This typically occurs if the form's auto-calculation setting is disabled or if the calculation order of the fields is incorrect. Check your PDF editor's form settings to ensure calculations are set to occur automatically, and verify that input fields are ordered before the calculation field.

How do I clear a field if a user mistakenly enters both a percentage and an amount?

You can add a custom validation or keystroke script to the input fields. For instance, you can script the 'Amount' field to clear the 'Percentage' field automatically when a value is entered, ensuring only one discount type is active at a time.

Can I use standard Excel formulas in PDF form fields?

No, PDF form calculations do not use standard Excel formulas. They rely on basic preset functions (like Sum, Product, Average) or require custom JavaScript for conditional logic, such as applying a discount based on multiple variables.