PDF Editing Issues

How to Merge PDF Form Fields with JavaScript

Steve KSteve K Oct 28, 2026 869 views

Question details

The user needs to combine the inputted values from multiple PDF form fields into one destination field using a slash separator.

How to Merge Values from PDF Form Fields Using JavaScript
Product
PDF
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Form Editing Mode

Open your PDF document in your PDF editor and enter the form editing mode (commonly found under the 'Prepare Form' or 'Form' tab).

2
Access Destination Field Properties

Right-click the destination text field where you want the merged result to appear, and select 'Properties' from the context menu.

3
Set Calculation Script

Navigate to the 'Calculate' tab in the Properties window. Select the option for 'Custom calculation script' and click the 'Edit' button.

4
Enter the JavaScript Code

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).

5
Save and Test

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.

Use a Custom Calculation Script to Merge Field Values
Case Sensitivity: JavaScript is case-sensitive. Make sure the field names you type into the script exactly match the actual field names in your PDF form.
Powerful PDF Editor

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. 1. Open Your PDF: Launch WPS Office and open your PDF document using the built-in PDF viewer.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the various tools for interactive forms.
  3. 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. 4. Save the Document: Once your form is perfectly configured, save the PDF document to ensure all interactive fields are preserved.
Easily create, edit, and fill interactive PDF forms.High compatibility with Adobe PDF formats and form fields.Lightweight alternative with a clean, familiar user interface.Comprehensive tools for adding text fields, checkboxes, and interactive elements.
microsoft office alternative - wps office

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.