How to Merge PDF Text Fields Based on Selected Checkboxes
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.

- 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.
Ensure your PDF editor supports JavaScript for interactive forms and that you have identified the exact names of your checkboxes and text fields.
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.
Right-click the destination text field where you want the combined text to appear and select 'Properties' from the context menu.
In the Text Field Properties dialog box, click on the 'Calculate' tab to set up the field's calculation logic.
Select the 'Custom calculation script' radio button, then click the 'Edit' button to open the JavaScript editor window.
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.
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.

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. Open WPS PDF: Launch WPS Office and open your interactive PDF document.
- 2. Navigate to Form Tools: Go to the 'Form' tab on the top ribbon to access the various form editing tools.
- 3. Manage Interactive Fields: Use the available options to add, modify, or seamlessly fill out text fields and checkboxes.
- 4. Save Your Progress: Click 'Save' or press Ctrl+S to keep your updated PDF form secure and ready for sharing.

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.




