How to Copy PDF Checkbox Selections in Order Using JavaScript
Question details
The user needs to populate a summary text field with the values of selected checkboxes in the exact sequence they were clicked, and dynamically remove them if the checkboxes are cleared.

- Product
- PDF / Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where a central summary field continuously updates to reflect real-time user checkbox selections in chronological order.
- Observed behavior
- Standard calculation scripts process form fields in a fixed predefined order, failing to capture the chronological order in which the user actually clicks the checkboxes.
Ensure you have access to a professional PDF editor that supports advanced form field properties and JavaScript execution, such as Adobe Acrobat Pro or WPS Office.
Use a Document-Level JavaScript Function Triggered by Mouse Up
This is the most reliable method for preserving the chronological selection order, as it actively appends or removes text the moment a user clicks a checkbox.
A calculation script processes fields in a fixed sequence based on field calculation order. To capture chronological clicks, you must use an event-driven approach. By binding a script to the 'Mouse Up' event of each checkbox, you can directly interact with the summary field precisely when the user makes a selection.
In your PDF editor's JavaScript tools, create a new document-level script. Write a function that takes the checkbox name as an argument, checks its state, and either appends the corresponding text value to the summary field or removes it.
Switch to form editing mode. Right-click the first checkbox in your document and select 'Properties' from the context menu.
Navigate to the 'Actions' tab within the Properties window. Choose 'Mouse Up' from the 'Select Trigger' dropdown menu.
Select 'Run a JavaScript' from the 'Select Action' dropdown and click 'Add'. Call your document-level function, passing the current checkbox's name as a parameter, then click 'OK' to save.
Repeat this trigger setup for every checkbox you want included in the summary field. Test the form to ensure checking and unchecking boxes updates the summary field sequentially.

Use a Field Calculation Script
A simpler alternative that groups checked items together, though it processes them in a fixed field order rather than chronological click order.
Create and Manage PDF Form Fields Easily with WPS Office
WPS Office provides a highly capable PDF editing suite that allows you to effortlessly design interactive forms, insert checkboxes, text fields, and customize field properties.
- 1. Open your PDF document: Launch WPS Office and open the PDF file you wish to turn into an interactive form.
- 2. Access form tools: Click on the 'Form' tab located on the top ribbon to reveal the interactive form controls.
- 3. Insert form fields: Select 'Check Box' or 'Text Field' from the toolbar, then click anywhere on the page to place the element.
- 4. Customize properties: Double-click the newly inserted form field to open its properties panel, where you can define names, appearances, and specific actions.
- 5. Save the interactive PDF: Once your form is completely set up, save the document to preserve all interactive fields and properties.

Frequently Asked Questions
Why doesn't a standard calculation script copy items in the order they were selected?
Standard calculation scripts process PDF form fields in a fixed sequence based on the document's predefined field calculation order, not the real-time chronological sequence of user clicks.
Can I remove a text item from the summary if the user unchecks the box?
Yes. By using a 'Mouse Up' event script directly on the checkbox, you can program logic to search for the specific text string in the summary field and replace or remove it when the checkbox state changes to 'Off'.
How do I trigger JavaScript when a PDF checkbox is clicked?
Open the checkbox Properties, navigate to the Actions tab, select 'Mouse Up' as your trigger, choose 'Run a JavaScript' from the select action dropdown, and click 'Add' to input your code.
What happens if the referenced text field is edited after the checkbox is selected?
If the source text field is dynamically edited after selection, the summary field will likely become out of sync unless you write complex synchronization scripts. It is highly recommended to make the referenced text fields read-only.




