How to Save Multiple Checkbox Values to a Text Field in PDF
Question details
The user needs a JavaScript solution to collect the export values of several selected checkboxes and output them into a single text field, separated by commas or semicolons.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where checking multiple options automatically consolidates the results into a single summary text field.
- Observed behavior
- Needs to properly join multiple active checkbox values into one text field without overwriting the variable for each selection.
Ensure your PDF form has all the required checkboxes and the target text field properly created and named before applying custom calculation scripts.
Use a JavaScript Array to Collect and Join Checkbox Values
This method pushes the export values of all actively selected checkboxes into an array, and then joins them into a single string to display in your target field.
Instead of overwriting a single variable for each checkbox, you can declare an array and check the state of each checkbox individually. If a checkbox is not 'Off' (meaning it is selected), its value is pushed to the array. Finally, the array is joined with a specific separator.
Right-click the target text field (e.g., Matrix_Test_Code) where you want the combined values to be displayed and select 'Properties'.
Navigate to the 'Calculate' tab in the Properties window, select 'Custom calculation script', and click the 'Edit' button to open the JavaScript editor.
Enter the following script to define an array and evaluate each checkbox: var values = []; if (this.getField('ACHE_S').value !== 'Off') values.push('ACHE_S'); if (this.getField('ACHE_T').value !== 'Off') values.push('ACHE_T'); event.value = values.join(', ');
Click 'OK' to save the script. Close the properties window and switch to 'Preview' mode. Test checking and unchecking the boxes to verify that the text field updates dynamically.

Manage PDF Forms and Fields with WPS Office
WPS Office provides powerful PDF editing features, allowing you to easily interact with, fill out, and manage interactive PDF forms without complex scripting requirements.
- 1. Open PDF in WPS: Launch WPS Office and open your interactive PDF document.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form features.
- 3. Fill and Manage Fields: Interact with text fields, checkboxes, and buttons natively without worrying about underlying code errors.
- 4. Save and Export: Save your completed document, maintaining full compatibility with all standard PDF viewers.

Frequently Asked Questions
Why is my text field only showing the last selected checkbox value?
This happens if you overwrite a single variable repeatedly (e.g., event.value = 'A'; event.value = 'B';). By using a JavaScript array and the .push() method, you collect all selected values and combine them at the end.
What does 'Off' mean in PDF checkbox JavaScript?
In PDF form calculations, 'Off' is the default value when a checkbox is unchecked. Checking if a field's value !== 'Off' ensures you only extract data from the boxes the user has actively checked.
Can I separate the joined values with semicolons instead of commas?
Yes. In the final line of your JavaScript code, change event.value = values.join(', '); to event.value = values.join('; '); to use a semicolon and a space as the separator.




