How to Populate a Single PDF Text Field with Multiple Checkbox Values Using JavaScript
Question details
The user needs to collect specific custom text messages from multiple selected checkboxes and display them inside a single read-only text field automatically.

- Product
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where ticking checkboxes triggers a script that cleanly compiles the corresponding text labels into a single summary text box.
- Observed behavior
- The text field must dynamically read the active status of each checkbox and append the corresponding string values, separated by commas, without syntax errors or overwriting existing selections.
Ensure your PDF editor supports JavaScript for form fields, and verify the exact names of your checkboxes (e.g., C1, C2) before writing the script.
Use an Array in a Custom Calculation Script
Apply a custom JavaScript calculation to the target text field to collect active checkbox values into an array, which perfectly handles joining text with commas.
Using simple concatenation (like +=) can lead to formatting errors, missing spaces, or unexpected syntax issues. By pushing active values into an array and using the join() method, the PDF will automatically place commas only where needed.
Open your PDF in form editing mode. Right-click the target text field where you want the combined text to appear and select Properties.
Under the General tab, check the 'Read Only' box so users cannot manually type over the calculated results.
Navigate to the Calculate tab, choose 'Custom calculation script', and click the Edit button.
Enter the following code to evaluate your checkboxes (assuming they are named C1 and C2): var values = []; if(this.getField("C1").value !== "Off") values.push("Best"); if(this.getField("C2").value !== "Off") values.push("Good"); event.value = values.join(", ");
Click OK to close the script editor, then close the Properties window. Toggle the checkboxes in your PDF to confirm the text field updates dynamically.

Create Interactive PDF Forms with WPS Office
WPS Office provides intuitive tools to easily create, edit, and manage dynamic PDF forms. You can insert checkboxes, text fields, and configure form properties to streamline document data collection.
- 1. Open Form Mode: Launch WPS Office, open your PDF file, and switch to the 'Form' tab on the top ribbon.
- 2. Insert Form Fields: Click 'Text Field' or 'Check Box' from the toolbar and draw them onto your document page.
- 3. Edit Properties: Double-click the inserted field to open the Properties panel, where you can modify its name, appearance, or set it as Read-Only.
- 4. Save Your Form: Save your document to apply the interactive properties, then test the fields to ensure they behave as expected.

Frequently Asked Questions
Why doesn't the plus-equals (+=) operator work well for joining PDF checkbox values?
Using standard string concatenation like += often leads to hanging commas when some options aren't selected, and it fails if the variable hasn't been properly initialized. Pushing valid selections into an array and using .join(", ") prevents these formatting issues.
How do I find the correct names for my PDF form fields in JavaScript?
You can view the exact name of your fields by opening the Form Field Properties window. The field name is displayed in the 'General' tab. Ensure your JavaScript matches these names exactly, as they are case-sensitive.
How can I trigger the text update immediately after a checkbox is clicked?
Make sure your checkboxes are set to commit their values immediately. In the Checkbox Properties, look under the 'Options' tab and verify that the setting to commit selected values immediately is enabled, which ensures the calculation script runs without requiring the user to click elsewhere.




