How to Automatically Add Text Before and After PDF Form Input
Question details
The user needs to automatically prepend and append fixed text or characters (such as quotation marks) to the text entered by a user in a PDF form field.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form where specific formatting or surrounding text is required automatically upon user data entry.
- Observed behavior
- The form field needs to dynamically update its value to enclose the user's raw input within predetermined characters or strings without destroying the original editable input.
Ensure you are using a PDF editor that supports form field properties and custom JavaScript execution, as basic PDF readers cannot run calculation scripts.
Apply a Custom JavaScript Calculation to the Text Field
Use a custom JavaScript calculation to automatically combine your fixed text with the entered value in the PDF form field.
To prevent the script from duplicating the fixed text every time the user edits the field, it is highly recommended to use two separate fields: a visible source field for user input, and a hidden or read-only calculation field to display the formatted text.
Add a standard text field to your PDF form where the user will type their data. Note the exact name of this field (e.g., 'InputField').
Add a second text field where the formatted text will appear. Right-click this field and select 'Properties'.
In the Properties dialog, navigate to the 'Calculate' tab.
Select the 'Custom calculation script' option, click 'Edit', and enter the following script: event.value = '"' + this.getField('InputField').value + '"'; (Replace 'InputField' with your actual source field name). Click 'OK' to save.
Edit and Fill PDF Forms Seamlessly with WPS Office
WPS Office provides a comprehensive PDF toolkit to edit, fill, and manage PDF forms effortlessly. Easily interact with document fields and enjoy full compatibility with standard PDF formats.
- 1. Launch WPS PDF: Open WPS Office and click on 'PDF' to launch the built-in PDF editor.
- 2. Open the Form: Import or drag-and-drop your interactive PDF form document into the workspace.
- 3. Fill the Fields: Use the 'Form' tab tools to easily interact with text fields, checkboxes, and dropdowns.
- 4. Save and Export: Once completed, securely save your PDF or export it to share with others.

Frequently Asked Questions
Why does the fixed text duplicate when I edit the field directly?
If you apply the custom calculation script directly to the input field, the script may run recursively, continually appending the text every time the field updates. This is why it is recommended to use a separate source field for user input and a different field for the calculated display.
Can I add text strings other than quotation marks?
Yes. You can replace the quotation marks in the script with any desired text. For example, to add a prefix and a suffix, use: event.value = 'Prefix ' + this.getField('FieldName').value + ' Suffix';
Will this script work on mobile PDF readers?
JavaScript support varies significantly on mobile devices. While advanced desktop PDF editors fully support these form calculations, many basic or default mobile PDF viewers may ignore the custom scripts.




