How to Automatically Copy Form Data When a Checkbox Is Selected in PDF
Question details
The user wants to automatically copy inputted values from one set of PDF form fields to another related set (like billing to shipping address) when a specific checkbox is ticked.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms where users often need to duplicate identical information across different sections.
- Observed behavior
- The user needs to implement a JavaScript trigger on a checkbox to automate form filling while allowing manual overwrites if needed.
Ensure that your PDF document already contains all the necessary source and destination text fields, and that each field has a unique and identifiable name.
Add a MouseUp JavaScript to the Checkbox
Attach a simple JavaScript code to the checkbox's action properties to copy values from the source fields to the destination fields automatically.
By configuring the checkbox properties in your PDF editor, you can trigger a custom script whenever the user clicks the box. The script retrieves the string value from your primary fields and pastes it into the secondary fields.
Right-click the targeted checkbox in your PDF form editing mode and select 'Properties' from the context menu.
Navigate to the 'Actions' tab. Select 'Mouse Up' from the 'Select Trigger' dropdown menu, and choose 'Run a JavaScript' from the 'Select Action' menu. Click the 'Add' button.
In the JavaScript Editor window, enter the following code: if (event.target.value != "Off") { this.getField("FirstName2").value = this.getField("FirstName1").valueAsString; this.getField("LastName2").value = this.getField("LastName1").valueAsString; } Customize the field names to match your form.
Click 'OK' to save the script, close the properties window, and test your form to ensure the data copies correctly when the box is checked.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides robust PDF editing capabilities, enabling you to easily insert checkboxes, manage text fields, and streamline data collection for your interactive forms.
- 1. Open your PDF Document: Launch WPS Office and open the PDF file you wish to make interactive.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form creation tools.
- 3. Insert Form Fields: Select the checkbox or text field tool and click on the document to place them exactly where you need.
- 4. Customize Properties: Double-click the inserted fields to rename them and adjust their properties for data collection.

Frequently Asked Questions
Can I copy data across multiple fields with one checkbox?
Yes, you can copy data to as many fields as necessary by adding additional lines inside the same 'if' statement in your JavaScript, such as this.getField("Address2").value = this.getField("Address1").valueAsString;
What happens if the user unchecks the box?
The provided script only copies data when the checkbox is selected. If you want the destination fields to clear when unchecked, you will need to add an 'else' statement to your JavaScript that sets the destination field values to empty strings.
Why is my JavaScript not working in the PDF?
Ensure that the field names referenced in your script perfectly match the actual names of the fields in your document. JavaScript is case-sensitive, so 'firstname1' is different from 'FirstName1'.




