How to Calculate Discount Amounts in PDF Forms
Question details
The user needs to configure a PDF form to automatically calculate a final result by subtracting a user-entered percentage from a base dollar amount.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form, such as an invoice or order form, that needs to automatically apply a percentage discount to a total dollar amount.
- Observed behavior
- The form requires a custom calculation script to correctly process the entered percentage and dollar amount inputs and accurately display the discounted total in the designated result field.
Verify that your form fields are created and perfectly match the names used in your script (e.g., 'Amount', 'Percentage', and 'Result'), as PDF JavaScript calculations are case-sensitive.
Use a Custom Calculation Script in the Result Field
Add a custom JavaScript code to the target result field to mathematically subtract the entered percentage from the base dollar amount.
PDF forms can handle complex mathematical operations using custom calculation scripts. By pulling the values from your 'Amount' and 'Percentage' fields, the script can calculate the final discounted price and display it dynamically.
Open your PDF form in editing mode. Right-click on the 'Result' text field where you want the final discounted amount to appear, and select 'Properties'.
Navigate to the 'Calculate' tab within the Properties window. Select the 'Custom calculation script' option to enable JavaScript input.
Click the 'Edit' button and input the following script: var amount = Number(this.getField("Amount").value); var percentage = Number(this.getField("Percentage").value); if (isNaN(amount) || isNaN(percentage)) { event.value = ""; } else { event.value = amount * (1 - percentage / 100); }
Switch to the 'Format' tab for the 'Result' field and set the format category to 'Currency'. This ensures the calculated number displays with a dollar sign and appropriate decimals.
Open the properties for your 'Percentage' field, go to the 'Format' tab, and set it to 'Number' or 'Percent'. If setting it to 'Percent', adjust your formula to use the corresponding decimal representation since 10% is stored as 0.10.

Create and Manage Interactive PDF Forms with WPS PDF
WPS Office provides robust and user-friendly PDF editing tools, allowing you to quickly create interactive forms, add editable text fields, and configure properties without needing complex software.
- 1. Open Your PDF in WPS Office: Launch WPS Office and click on the PDF module to open your existing document or create a new one.
- 2. Access Form Editing Tools: Navigate to the 'Form' tab on the top ribbon to access the suite of interactive form creation tools.
- 3. Insert Text Fields: Click on 'Text Field' and draw the boxes on your document where users will input their amounts and percentages.
- 4. Configure Field Properties: Double-click any inserted field to open its properties panel, where you can rename the field and set formatting rules.
- 5. Save and Distribute: Once your fields are configured, save the document as a standard PDF to retain all interactive form functionalities.

Frequently Asked Questions
Why is my PDF form calculation returning a blank value?
This usually happens if the field names in your JavaScript code do not exactly match the actual field names assigned in the form properties. Ensure there are no typos or trailing spaces in the field names.
Does the percentage field need to include the percent sign (%)?
It depends on how you configure the field format. If users enter '10' for 10%, formatting it as a standard 'Number' works best with the (percentage / 100) formula. If formatted as a 'Percent' field, the system may treat 10% as 0.10, requiring you to adjust the script to avoid dividing by 100 twice.
Can I perform this discount calculation without JavaScript?
Standard PDF form features allow for simple addition, subtraction, or multiplication. However, combining operations like subtracting a percentage from a base amount dynamically requires a custom JavaScript calculation script.
How do I ensure the calculated discount displays as a currency?
In the form editing mode, double-click the Result field to open its Properties. Under the Format tab, select 'Currency' from the category dropdown. This will automatically prepend the local currency symbol and format the number to two decimal places.




