Swap Two PDF Form Field Values Using a Checkbox in Adobe Acrobat
Question details
The user wants to exchange the content of two specific text fields in a PDF form by checking or unchecking a checkbox using a custom script.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form that requires dynamic data switching based on a user's checkbox interaction.
- Observed behavior
- The user needs to trigger a value exchange between two text fields when the checkbox state changes.
Ensure you have Adobe Acrobat Pro or an advanced PDF editor that supports interactive form creation and JavaScript execution. Note the exact field names of the two text fields you wish to swap.
Add a JavaScript Action to the Checkbox Mouse Up Event
Use a custom JavaScript snippet in the checkbox properties to automatically pull and swap the values of two defined text fields when the user clicks the checkbox.
This method uses the built-in JavaScript engine in Adobe Acrobat to dynamically retrieve the values of two fields and swap them based on a trigger event. The 'Mouse Up' event is the standard trigger for checkbox interactions.
Open your PDF document in Adobe Acrobat, navigate to the 'Tools' menu, and select 'Prepare Form' to enter the form editing mode.
Right-click the target Checkbox field and select 'Properties' from the context menu.
Go to the 'Actions' tab. Select 'Mouse Up' from the 'Select Trigger' dropdown. Under 'Select Action', choose 'Run a JavaScript', and then click the 'Add' button.
In the JavaScript Editor window, paste the following code: var a = this.getField("Text1"); var b = this.getField("Text2"); var a1 = a.value; var b1 = b.value; a.value = b1; b.value = a1;
Change "Text1" and "Text2" in the script to the exact names of your form's text fields. Click 'OK' to save the script, then click 'Close' on the Properties dialog. Test your form by clicking the checkbox to see the values swap.

Edit and Manage PDF Forms Easily with WPS Office
While advanced JavaScript authoring is typically done in Acrobat Pro, WPS Office features a robust and user-friendly PDF toolkit. It allows you to quickly view, fill out, and manage interactive PDF forms without the need for an expensive subscription.
- 1. Install WPS Office: Download and install the free WPS Office suite on your Windows, Mac, or mobile device.
- 2. Open Your PDF Form: Launch WPS PDF and open the interactive PDF document you need to work with.
- 3. Interact and Edit: Use the built-in form tools to comfortably fill out text fields, toggle checkboxes, and save your document securely.

Frequently Asked Questions
Why isn't the JavaScript swapping the values when I click the checkbox?
This usually happens if the field names referenced in the script (like "Text1" or "Text2") do not perfectly match the actual names of your text fields. Double-check your form fields for exact spelling and case sensitivity.
Can I prevent the values from swapping back if the user unchecks the box?
Yes. The basic script provided triggers every time the mouse click is released. To make the swap dependent on whether the box is checked or unchecked, you can wrap your swap logic in an 'if' statement checking the event.target.value of the checkbox.
Does this JavaScript work on mobile PDF readers?
Most mobile PDF viewers and basic web browsers do not fully support advanced JavaScript for form fields. This feature is best utilized and guaranteed to work on robust desktop PDF applications.




