PDF Editing Issues

How to Merge PDF Text Fields Based on Selected Checkboxes

Aamir Naveed AkramAamir Naveed Akram Nov 5, 2026 868 views

Question details

The user wants to dynamically combine text from multiple text fields into a single destination field, conditional on the user selecting corresponding checkboxes in a PDF form.

How to Merge PDF Text Fields Based on Selected Checkboxes
Product
PDF Editor
Device & OS
not provided
Scenario
Creating interactive PDF forms with conditional text merging and advanced scripting.
Observed behavior
The user needs a custom calculation script that checks the state of multiple checkboxes and appends the linked text fields to a target destination field.
Before you start

Ensure your PDF editor supports JavaScript for interactive forms and that you have identified the exact names of your checkboxes and text fields.

Solution 1Recommended

Use Custom JavaScript to Merge Text Fields

Apply a custom calculation script to the destination field that checks each checkbox's state and appends the corresponding text.

This method uses a JavaScript loop to iterate through a sequence of numbered checkboxes. If a checkbox is selected (meaning its value is not 'Off'), the script pulls the value from its paired text field and adds it to the destination field.

1
Open Field Properties

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

2
Access the Calculate Tab

In the Text Field Properties dialog box, click on the 'Calculate' tab to set up the field's calculation logic.

3
Enable Custom Scripting

Select the 'Custom calculation script' radio button, then click the 'Edit' button to open the JavaScript editor window.

4
Input the JavaScript

Paste the following script into the editor: `event.value = ""; for (var i = 1; i <= 10; i++) { if (this.getField("cb" + i).valueAsString != "Off") event.value += this.getField("t" + i).valueAsString + " "; }`. Adjust the field prefixes ('cb' for checkboxes, 't' for text fields) and the loop limit (10) to accurately match the structure of your form.

5
Save and Test

Click 'OK' to save the script, then close the Properties window. Interact with your form by checking and unchecking the boxes to verify that the destination text field updates automatically.

Use Custom JavaScript to Merge Text Fields
Field Naming Convention: For the loop in the script to function correctly, ensure your form fields are named sequentially, such as cb1, cb2, and t1, t2.

Easily Edit and Fill PDF Forms with WPS PDF

WPS Office provides a powerful, lightweight PDF editor that allows you to manage interactive forms, fill out data, and secure your documents with ease.

  1. 1. Open WPS PDF: Launch WPS Office and open your interactive PDF document.
  2. 2. Navigate to Form Tools: Go to the 'Form' tab on the top ribbon to access the various form editing tools.
  3. 3. Manage Interactive Fields: Use the available options to add, modify, or seamlessly fill out text fields and checkboxes.
  4. 4. Save Your Progress: Click 'Save' or press Ctrl+S to keep your updated PDF form secure and ready for sharing.
Create, edit, and fill interactive PDF forms seamlessly.Highly compatible with standard Adobe PDF form fields and elements.Lightweight software with an intuitive, user-friendly interface.Seamlessly convert PDFs to Word, Excel, and other Office formats.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my destination text field updating when I click the checkbox?

This usually happens if the calculation script contains a syntax error or if the exact names of your checkboxes and text fields do not match the variables defined in your script (e.g., 'cb1' vs 'Checkbox1'). Double-check the exact spelling and capitalization in the field Properties under the General tab.

How can I change the names of the fields in the JavaScript?

In the provided script, replace the string 'cb' inside `this.getField("cb" + i)` with the actual prefix of your checkbox fields, and 't' with the prefix of your text fields. Also, ensure the loop condition `i <= 10` reflects the total number of fields you are evaluating.

Can I add a comma between the merged text values?

Yes. You can modify the string appended in the script. Instead of adding a space `+ " "`, you can use `+ ", "` so that each text field's value is separated by a comma and a space. Keep in mind you may want to add extra logic to strip the trailing comma at the very end of the string.

Will this JavaScript calculation work on mobile PDF readers?

Custom JavaScript calculations in PDF forms are generally well-supported on robust desktop PDF editors like Adobe Acrobat. However, many mobile PDF readers lack full JavaScript execution engines, meaning the fields may not merge dynamically when viewed or edited on mobile devices.