How to Copy Checkbox Values to Empty PDF Form Fields via JavaScript
Question details
The user needs to copy text from a source field into the first available read-only PDF form field automatically when a checkbox is checked, while preserving any previously copied data.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where checking a box transfers a value to a list of sequential read-only fields.
- Observed behavior
- The text should be copied into the first empty sequential field without overwriting existing values in previously filled fields.
Ensure your PDF editor supports JavaScript for form fields, and note the exact names of your source field, checkbox, and target sequential fields before writing the script.
Use a For Loop in the Checkbox Mouse Up Event
The most efficient way to find the first empty field in a sequence is by using a JavaScript 'for' loop triggered by the checkbox's Mouse Up event.
This method loops through your target fields (e.g., Correctives1copy, Correctives2copy) and inserts the source value into the first one that is completely empty. It prevents overwriting data copied from previous checkbox actions.
Right-click the target checkbox in Form Editing mode and select 'Properties'.
Go to the 'Actions' tab, select 'Mouse Up' as the trigger, and choose 'Run a JavaScript' as the action, then click 'Add'.
Input the following script: `if (event.target.value != 'Off' && this.getField('Correctives1').value != '') { for (var i = 1; i <= 3; i++) { var target = this.getField('Correctives' + i + 'copy'); if (target.value == '') { target.value = this.getField('Correctives1').value; break; } } }`
Click 'OK' to save the script, exit form editing mode, and click the checkbox to verify the value transfers correctly to the first empty field.

Use Sequential If-Else Statements
If you only have a few target fields, a hardcoded if-else chain can be used instead of a loop to check each field sequentially.
Create and Manage Interactive PDF Forms in WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily create interactive forms, add checkboxes, text fields, and configure properties without needing expensive specialized software.
- 1. Open Your PDF in WPS: Launch WPS Office and open your PDF document using the WPS PDF tool.
- 2. Enter Form Editing Mode: Navigate to the 'Form' tab on the top ribbon to access all interactive field controls.
- 3. Add Checkboxes and Fields: Click on the 'Check Box' or 'Text Field' icons to place them onto your document page.
- 4. Configure Properties: Double-click any inserted field to open its properties panel, where you can set names, appearances, and behaviors.
- 5. Save the Interactive Form: Once configured, save your document. The form is now ready to be filled out by users.

Frequently Asked Questions
Why is the script overwriting the first field instead of moving to the second?
This usually happens if the script does not check whether the target field is empty (`if (target.value == '')`) before copying the data, or if the `break;` command is missing from the loop, which stops the code from filling subsequent fields.
Do I put the JavaScript on the text field or the checkbox?
The script should be placed in the checkbox's 'Mouse Up' action. This ensures the code only runs when the user actively clicks and releases the checkbox.
How do I alert the user if all destination fields are full?
You can declare a variable to track if a successful copy occurred during the loop. If the loop completes and the variable is still false, trigger an alert using `app.alert('All target fields are currently full.');`.
Will this JavaScript work in all PDF readers?
Not all PDF readers support advanced JavaScript form actions. For the best compatibility, users should fill out the form using robust PDF applications like WPS PDF or Adobe Acrobat.




