Other PDF Issues

Swap Two PDF Form Field Values Using a Checkbox in Adobe Acrobat

Kushani NimanthikaKushani Nimanthika Nov 5, 2026 869 views

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.

How to Swap Two Field Values with a Checkbox in Acrobat
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.
Before you start

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.

Solution 1Recommended

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.

1
Enter Edit Form Mode

Open your PDF document in Adobe Acrobat, navigate to the 'Tools' menu, and select 'Prepare Form' to enter the form editing mode.

2
Open Checkbox Properties

Right-click the target Checkbox field and select 'Properties' from the context menu.

3
Add a JavaScript Action

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.

4
Input the Swap Script

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;

5
Customize and Save

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.

Add a JavaScript Action to the Checkbox Mouse Up Event
Match Field Names Exactly: JavaScript is case-sensitive. Ensure that the field names inside the getField() parentheses exactly match the names of the text fields on your PDF, including capital letters and spacing.
Powerful PDF Form Editor

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. 1. Install WPS Office: Download and install the free WPS Office suite on your Windows, Mac, or mobile device.
  2. 2. Open Your PDF Form: Launch WPS PDF and open the interactive PDF document you need to work with.
  3. 3. Interact and Edit: Use the built-in form tools to comfortably fill out text fields, toggle checkboxes, and save your document securely.
Fully compatible with standard PDF forms, including checkboxes and text fieldsLightweight application that loads large PDFs quickly on any deviceEasily fill, edit, sign, and print interactive PDFsCost-effective alternative to expensive PDF editing software
microsoft office alternative - wps office

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.