How to Merge PDF Form Fields with JavaScript
Question details
The user needs to combine the inputted values from multiple PDF form fields into one destination field using a slash separator.

- Product
- Device & OS
- not provided
- Scenario
- Creating or editing an interactive PDF form where data from several individual text fields needs to be aggregated into a single field automatically.
- Observed behavior
- Values from individual fields (e.g., A, B, and C) need to be concatenated automatically into a destination field (e.g., resulting in A/B/C) using a calculation script.
Ensure you are using a PDF editor that supports interactive form creation and JavaScript calculations, and note down the exact names of the form fields you intend to merge.
Use a Custom Calculation Script to Merge Field Values
Apply a simple JavaScript snippet to the destination field's calculation properties to automatically concatenate the values of the source fields.
By setting up a custom calculation script, your PDF form will automatically update the destination field whenever the user inputs data into the source fields. This method relies on standard Acrobat JavaScript.
Open your PDF document in your PDF editor and enter the form editing mode (commonly found under the 'Prepare Form' or 'Form' tab).
Right-click the destination text field where you want the merged result to appear, and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab in the Properties window. Select the option for 'Custom calculation script' and click the 'Edit' button.
Enter the following script into the editor: event.value = this.getField("A").valueAsString + "/" + this.getField("B").valueAsString + "/" + this.getField("C").valueAsString; (Ensure you replace "A", "B", and "C" with the exact names of your source fields).
Click 'OK' to save the script, then close the Properties window. Exit form editing mode and type values into your source fields to verify that the destination field updates correctly.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office offers a comprehensive built-in PDF editor that makes it easy to create fillable forms, edit text, and manage PDF documents. It provides a lightweight, user-friendly interface for all your document needs.
- 1. Open Your PDF: Launch WPS Office and open your PDF document using the built-in PDF viewer.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the various tools for interactive forms.
- 3. Add or Edit Fields: Use the toolbar to insert text fields, checkboxes, or buttons. Double-click any field to modify its properties and styling.
- 4. Save the Document: Once your form is perfectly configured, save the PDF document to ensure all interactive fields are preserved.

Frequently Asked Questions
Can I use a different separator instead of a slash?
Yes, you can replace the slash ("/") in the JavaScript code with any character or string you prefer, such as a hyphen ("-"), comma (","), or simply a space (" ").
Why isn't my destination field updating automatically?
Ensure that the calculation order in your PDF form is set correctly. If the destination field is calculated before the source fields are processed, the result won't reflect the most recent changes.
What happens if one of the source fields is left blank?
If a source field is blank, the simple concatenation script will still output the separator (e.g., resulting in 'aaa//ccc'). To prevent extra separators, you can use JavaScript 'if' statements to check if a field contains data before appending its value.




