PDF Editing Issues

How to Validate a PDF Form Field Against a Percentage of Another Field

John WilsonJohn Wilson Nov 2, 2026 869 views

Question details

The user needs to restrict a PDF form field ('Fringe') so it does not exceed 40% of another field ('Salary') using custom validation.

How to Validate a PDF Form Field Against a Percentage of Another Field
Product
PDF Form Editors
Device & OS
not provided
Scenario
Creating an interactive PDF form where user input must be validated and blocked if it exceeds a calculated percentage based on another field.
Observed behavior
Currently, the form allows any value to be entered. The desired goal is to automatically evaluate the input and trigger an error message when the limit is exceeded.
Before you start

Ensure that both the source field ('Salary') and the target field ('Fringe') are created as text or number fields in your PDF form, and note down their exact field names since JavaScript references are case-sensitive.

Solution 1Recommended

Implement Custom JavaScript Validation for PDF Fields

Use a custom validation script in your PDF editor to automatically check the entered value against 40% of the Salary field and block invalid entries.

A custom validation script can block invalid input from being entered into a field and display warning messages simultaneously. By setting the event.rc property to false, the system knows the input failed validation.

1
Open Field Properties

Open your PDF in form editing mode, right-click the target field (e.g., 'Fringe'), and select 'Properties' from the context menu.

2
Navigate to the Validate Tab

In the Properties window, click on the 'Validate' tab. Select the option that says 'Run custom validation script'.

3
Enter the JavaScript Code

Click 'Edit' and enter the following JavaScript code: var salary = Number(this.getField("Salary").value); var fringe = Number(event.value); event.rc = salary !== 0 && fringe <= salary * 0.4; if (!event.rc) app.alert("Fringe must not exceed 40% of Salary.");

4
Save and Test

Click 'OK' to save the script, close the properties window, exit form editing mode, and test the validation by entering a value higher than 40% of the Salary field.

Implement Custom JavaScript Validation for PDF Fields
Handling Zero and Blank Values: The script includes 'salary !== 0' to prevent validation errors or division-by-zero alerts if the main Salary field is currently left blank by the user.

View and Manage PDF Forms Easily with WPS Office

WPS Office provides a comprehensive PDF toolkit that allows you to seamlessly view, interact with, and manage PDF forms without needing complex or heavy setups.

  1. 1. Install WPS Office: Download and install WPS Office Free on your device.
  2. 2. Open Your PDF: Launch WPS PDF and open your interactive PDF document.
  3. 3. Interact with Forms: Navigate to the 'Form' tab to interact with, highlight, or fill out form fields intuitively.
  4. 4. Save securely: Save your completed PDF or export it securely to share with others.
Seamlessly fill out and edit interactive PDF formsHighly compatible with standard Adobe PDF formats and form elementsLightweight application that runs smoothly on Windows, Mac, and mobile devicesIncludes OCR, page management, and format conversion tools built-in
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't the validation script trigger as soon as I start typing?

Validation scripts in PDF forms generally run only when the field loses focus, meaning you have to click outside the field or press the Tab key to trigger the check and the alert.

How can I change the percentage limit in the script?

You can easily update the decimal multiplier in the code. For instance, change '0.4' to '0.5' if you want a 50 percent limit instead of 40 percent.

Can I apply this JavaScript validation to multiple fields?

Yes, but you will need to copy the custom script into the validation properties of each specific target field individually and ensure the source field names are correctly referenced.

What happens if the Salary field is empty when I fill out Fringe?

The script specifically includes a check (salary !== 0) to handle empty or zero-value fields gracefully. This prevents incorrect validation alerts from firing before the user has had a chance to fill out the primary field.