PDF Editing Issues

How to Display Custom Messages Based on PDF Form Values using JavaScript

Nimra MalikNimra Malik Nov 5, 2026 869 views

Question details

The user needs to display a specific text code or message in a PDF form when a numeric field contains a matching value.

How to Display Custom Messages Based on PDF Form Values
Product
PDF
Device & OS
not provided
Scenario
Creating or editing interactive PDF forms where numeric inputs need to be automatically translated into predefined text codes.
Observed behavior
Looking for the appropriate Acrobat JavaScript approach to either replace the entered numeric value with a text code or populate a different field with the corresponding message.
Before you start

Ensure your PDF editing software supports JavaScript for interactive form fields. Familiarize yourself with accessing form field properties and navigating to the Validate or Calculate tabs.

Solution 1Recommended

Use a Custom Validation Script to Replace the Entered Value

Apply a custom validation script if you want the numeric value entered by the user to be immediately replaced by a specific text code within the same field.

This method uses a JavaScript validation script directly on the input field. When the user enters a specific number and exits the field, the script evaluates the input and automatically replaces it with the corresponding text string.

1
Access form editing mode

Open your interactive PDF in your PDF editor (such as Adobe Acrobat) and enter Form Editing mode.

2
Open field properties

Right-click the numeric input text field and select 'Properties' from the context menu.

3
Navigate to the Validate tab

In the Properties dialog box, click on the 'Validate' tab to set up custom data validation rules.

4
Enter the JavaScript code

Select 'Run custom validation script' and click 'Edit'. Enter the following code: if (event.value == 0.8) { event.value = 'Code 1A'; } else if (event.value == 0.95) { event.value = 'Code 1B'; } Click OK to save.

Use a Custom Validation Script to Replace the Entered Value
Script Customization: You can add as many 'else if' statements as you need to cover all possible numeric values and their corresponding codes.
Advanced PDF Form Management

Create and Manage Interactive PDF Forms with WPS Office

WPS Office provides a comprehensive suite of PDF tools, allowing you to easily view, fill, create, and manage interactive PDF forms without needing heavy or expensive software.

  1. 1. Download and install WPS Office: Get the free version of WPS Office from the official website and install it on your device.
  2. 2. Open your PDF form: Launch WPS Office and open your interactive PDF file directly within the application.
  3. 3. Fill and manage the form: Use the built-in PDF tools to interact with form fields, input data, and leverage smart document features.
  4. 4. Save and export: Save your filled PDF form securely or share it directly from the WPS interface.
Effortlessly fill and interact with complex PDF formsHigh compatibility with Adobe Acrobat PDF formats and interactive elementsLightweight, fast, and user-friendly interface for seamless document handlingAll-in-one suite combining PDF, Word, Excel, and Presentation tools
microsoft office alternative - wps office

Frequently Asked Questions

Will these JavaScript validation rules work in all PDF viewers?

Not necessarily. While they will work perfectly in advanced PDF editors like Adobe Acrobat, basic browser-based PDF viewers or simple mobile apps might not support executing embedded JavaScript in interactive forms.

Can I use strings instead of numbers for the validation trigger?

Yes. You can modify the JavaScript to evaluate text strings by placing the target value in quotation marks, such as: if (event.value == "Apple") { event.value = "Code A"; }

Why is my custom calculation script not updating immediately?

Calculation scripts typically trigger when a field loses focus. Ensure that you have pressed 'Enter' or clicked outside the numeric input field for the JavaScript to execute and update the target field.

How do I clear the custom message if the numeric field is left blank?

You can add a condition at the beginning of your script to check for a blank value: if (event.value == "") { event.value = ""; } to ensure the field resets properly when data is deleted.