How to Append Text to a PDF Form Field Without Repeating
Question details
The user needs to automatically append a specific unit (such as "lbs.") to the numeric value entered into a PDF form field without the text duplicating.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Setting up automated formatting or calculation scripts for interactive PDF form fields.
- Observed behavior
- When placing the appending script in the format field, the unit repeatedly appends itself (e.g., "170 lbs. lbs.") every time the user enters values into other fields on the same form.
Ensure you are using a PDF editor that supports JavaScript for interactive forms, and verify that the form editing mode is currently active.
Use a Custom Validation Script Instead of a Format Script
By moving the JavaScript code from the formatting tab to the validation tab, the script will only execute when the specific field's value changes, preventing repeated text duplication.
When a formatting script is used in a PDF form, the application recalculates and reapplies the format every time any field in the document is updated. This causes text like "lbs." to be appended endlessly. Placing the script inside the Validation settings ensures it triggers exactly once—right after the user inputs data into that specific field.
Right-click the target text field in your PDF form and select "Properties" from the context menu.
Click on the "Validate" tab at the top of the Properties dialog box. Do not use the "Format" tab for this specific action.
Select the "Run custom validation script" option and click "Edit". Enter your JavaScript code, ensuring it checks the value first, for example: `if (event.value) { event.value = event.value + " lbs."; }`.
Click "OK" to save the script, close the Properties window, and exit form editing mode to test your field.

Create and Edit PDF Forms Seamlessly with WPS Office
WPS Office offers a comprehensive PDF toolkit that allows you to easily design interactive forms, edit text, and manage document properties. It is a lightweight, all-in-one solution for your productivity needs.
- 1. Open your PDF: Launch WPS Office and open the PDF document containing the forms you want to edit.
- 2. Access the Form tools: Navigate to the "Form" tab on the top ribbon to access all interactive form creation and editing tools.
- 3. Modify form field properties: Double-click any text field to open its properties, where you can adjust formatting, validation, and calculation settings.
- 4. Save your document: Once your fields are configured correctly, click the Save icon to apply the changes to your interactive PDF.

Frequently Asked Questions
Why does my PDF form field duplicate the appended text?
This happens when the script appending the text is placed in the 'Format' tab. PDF readers trigger format scripts every time any field on the form recalculates, causing the text to duplicate. Moving the script to the 'Validate' tab fixes this.
Can I use JavaScript to prepend text instead of appending it?
Yes. Inside the custom validation script, you can arrange the text string to appear before the field value. For example, using the script `event.value = "Prefix Text " + event.value;` will add your desired text before the user's input.
Will these custom validation scripts work on mobile PDF readers?
Support for PDF JavaScript varies greatly across mobile applications. While desktop applications like WPS Office and Adobe Acrobat handle them perfectly, many default mobile PDF viewers may ignore custom validation scripts entirely. It is recommended to have users fill out complex forms on a desktop.




