PDF Editing Issues

How to Create a Custom Percentage Validation Script for PDF Forms

Elise WilliamsElise Williams Oct 28, 2026 869 views

Question details

The user wants to create PDF form fields that accept custom percentage values (from 0 to 100) and use JavaScript to validate that the total sum does not exceed 100.

How to Create a Custom Percentage Validation Script for PDF Forms
Product
PDF
Device & OS
not provided
Scenario
Designing an interactive PDF form where users input multiple percentage values, requiring a script to ensure the total is mathematically valid without disrupting the filling process.
Observed behavior
The user needs a reliable method to validate percentage inputs, prevent totals over 100, and handle error messages seamlessly without relying on repeated pop-up alerts.
Before you start

Ensure you are using a PDF editor that supports advanced form field properties and custom JavaScript calculations, such as Adobe Acrobat Pro or a fully-featured PDF form builder.

Solution 1Recommended

Configure Field Properties and Custom Validation Script

Adjust the form field formats to handle standard numbers and use a custom JavaScript function to quietly validate the total.

Using the built-in 'Percentage' format can sometimes cause data entry confusion (e.g., typing '1' might register as 100%). It is best to use a standard 'Number' format and handle the validation manually.

Additionally, triggering pop-up alerts while the user is still inputting data can lead to a frustrating experience. It is better to use subtle visual cues or dedicated message fields.

1
Change field format to Number

Open the form field properties for your percentage inputs. Navigate to the Format tab and change the format category from 'Percentage' to 'Number'. This ensures that an input of 1 is treated strictly as 1.

2
Create a total calculation script

In the calculation tab of your 'Total' field, add a custom JavaScript to sum the values of all the corresponding percentage fields.

3
Apply validation logic for maximum total

In the validation tab or your custom script, write an if-statement to check if the calculated total exceeds 100. If it does, use the code 'event.rc = false;' to immediately reject the invalid input.

4
Use a message field for errors

Instead of using 'app.alert()' for values under 100%, create a read-only text field next to the total. Update this text field's value to display an error or warning message only when necessary, preventing disruptive pop-ups while the user is still filling out the form.

Configure Field Properties and Custom Validation Script
Best Practice: Using conditional color changes (e.g., turning the total text red when it exceeds 100) is often the most user-friendly way to indicate validation errors.
Comprehensive PDF Toolkit

Create and Manage Interactive PDF Forms with WPS Office

If you are looking to design robust, interactive PDF documents, WPS Office offers an intuitive PDF editor equipped with powerful form-building and editing capabilities.

  1. 1. Open your document in WPS PDF: Launch WPS Office and open the PDF file you wish to turn into an interactive form.
  2. 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to reveal various interactive field options.
  3. 3. Insert and configure fields: Click on 'Text Field' to place a box on your document. Double-click the field to customize its properties, appearance, and input formatting.
Easily add, edit, and manage interactive text fields, checkboxes, and buttonsHighly compatible with standard PDF formats and standard form structuresLightweight, fast, and features a user-friendly interface
microsoft office alternative - wps office

Frequently Asked Questions

Why shouldn't I use the built-in Percentage format for my PDF form fields?

The built-in Percentage format often automatically multiplies the entered value by 100. For example, if a user types '1' intending it to mean 1%, the software may convert it to 100%. Using the Number format prevents this confusion.

What does event.rc = false do in Adobe Acrobat JavaScript?

In PDF JavaScript validation, setting event.rc to false rejects the user's current keystroke or input. It prevents the field from accepting the invalid value and reverts it to its previous state.

How can I show an error message without an annoying pop-up?

You can design a read-only text field specifically for messages. Use your validation script to change the text content or text color of this field dynamically based on whether the total input is valid or invalid.