How to Display Selected Checkboxes as a Comma-Separated List in PDF
Question details
The user needs to create a calculated text field in a PDF form that dynamically aggregates and displays the names of selected checkboxes, separated by commas.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form where checking multiple options (e.g., currency checkboxes) automatically generates a summary text string.
- Observed behavior
- A dynamic text string separated by commas updates automatically based on which checkboxes are currently ticked.
Ensure you are using a PDF editor that supports form field editing and custom JavaScript calculations, and verify that your checkboxes have unique, specific names (e.g., 'USD', 'EUR').
Use a Custom Calculation JavaScript
Apply a custom JavaScript snippet to the target text field's properties to check the state of specific checkboxes and join their names together.
PDF forms support JavaScript to create dynamic interactions. By looping through a defined array of checkbox field names, the script can check if each box is checked (not 'Off') and push the names into an array. Finally, the array is joined into a single string with a comma separator.
Open your PDF in form editing mode. Right-click your checkboxes, select 'Properties', and note down the exact 'Name' of each checkbox (for example, 'USD' and 'EUR').
Insert a Text Field where you want the comma-separated list to appear. Right-click this new Text Field and select 'Properties'.
Navigate to the 'Calculate' tab inside the Text Field Properties window. Select the option labeled 'Custom calculation script'.
Click the 'Edit' button and paste the following code: var fields = ["USD", "EUR"]; var selected = []; for (var i in fields) { var f = this.getField(fields[i]); if (f.valueAsString != "Off") selected.push(f.name); } event.value = selected.join(", ");
Click 'OK' to save the script, then close the Properties window. Exit form editing mode and test your form by checking and unchecking the boxes to see the text field update automatically.

Create Interactive PDF Forms with WPS Office
WPS Office provides robust PDF editing capabilities, enabling you to insert checkboxes, manage text fields, and customize form properties. Build professional, interactive forms seamlessly without the need for heavy or expensive software.
- 1. Open Your PDF: Launch WPS Office and open your PDF document.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access interactive controls.
- 3. Insert Form Elements: Select the Checkbox or Text Field icons to insert them directly onto your document.
- 4. Customize Properties: Double-click the inserted fields to rename them, adjust their appearance, and set up interactive rules.

Frequently Asked Questions
Can I separate the checkbox values with a line break instead of a comma?
Yes. In the script, change the last line to event.value = selected.join("\n");. Additionally, make sure to enable the 'Multi-line' option in the 'Options' tab of your Text Field's properties so the breaks display correctly.
Why does my text field not update immediately when I click a checkbox?
This can happen if the form's calculation order is incorrect or if the checkboxes don't trigger the calculation. To fix this, you can open the properties of your checkboxes, go to the 'Options' tab, and ensure 'Commit selected value immediately' is checked.
How do I display a custom text string instead of the checkbox field name?
If you want to display the checkbox's 'Export Value' instead of its internal field name, change selected.push(f.name); to selected.push(f.valueAsString); in the script. Ensure you have set the desired text as the Export Value in the checkbox properties.




