PDF Editing Issues

How to Copy Checkbox Values to Empty PDF Form Fields via JavaScript

Olivia MillerOlivia Miller Nov 5, 2026 869 views

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.

How to Copy Checkbox Values to Empty PDF Form Fields using JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

Right-click the target checkbox in Form Editing mode and select 'Properties'.

2
Navigate to Actions

Go to the 'Actions' tab, select 'Mouse Up' as the trigger, and choose 'Run a JavaScript' as the action, then click 'Add'.

3
Enter the JavaScript Code

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; } } }`

4
Save and Test

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 a For Loop in the Checkbox Mouse Up Event
Add an Alert for Full Fields: You can add logic after the loop to trigger an `app.alert()` notifying the user if all target fields are already full.
WPS PDF Editor

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. 1. Open Your PDF in WPS: Launch WPS Office and open your PDF document using the WPS PDF tool.
  2. 2. Enter Form Editing Mode: Navigate to the 'Form' tab on the top ribbon to access all interactive field controls.
  3. 3. Add Checkboxes and Fields: Click on the 'Check Box' or 'Text Field' icons to place them onto your document page.
  4. 4. Configure Properties: Double-click any inserted field to open its properties panel, where you can set names, appearances, and behaviors.
  5. 5. Save the Interactive Form: Once configured, save your document. The form is now ready to be filled out by users.
Easily insert text fields, checkboxes, and radio buttons into any PDFHighly compatible with standard PDF form formats and Adobe Acrobat featuresLightweight application that runs smoothly on low-spec PCsFree alternative with an intuitive, tabbed interface
microsoft office alternative - wps office

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.