How to Move an Acrobat Form Field Based on Another Field's Selection
Question details
The user wants to know how to dynamically change the position of one PDF form field when a specific value is selected in a different form field.

- Product
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where the layout or field placement needs to adapt automatically based on user choices.
- Observed behavior
- The user requires a programmatic method to manipulate the field coordinates based on the selection made in another controlling field.
Ensure you have access to advanced PDF form editing tools that support JavaScript actions, and note the initial coordinates of the field you wish to move.
Use JavaScript to Modify the Target Field's Rect Property
You can dynamically reposition fields by writing a custom action or validation script on the controlling field using the rect property.
In interactive PDF forms, every form field has a 'rect' property that represents its physical boundaries on the page. This property is defined by an array of four coordinate points: the upper-left and lower-right corners.
By assigning a JavaScript action to the controlling field (such as a dropdown or radio button), you can test the selected value and assign a completely new set of coordinates to the target field, effectively moving it.
Enter form editing mode, right-click the controlling field (e.g., your dropdown menu), and select 'Properties'.
Go to the 'Actions' or 'Format/Validate' tab, select 'Run a JavaScript' as the action type, and click 'Add'.
Write a JavaScript conditional statement to check the user's selection, for example: if (event.value == 'Choice1') { ... }
Inside your condition, update the target field's coordinates using the syntax: this.getField('TargetField').rect = [left, top, right, bottom];

Easily Manage and Edit PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to create, edit, and interact with PDF forms effortlessly. Whether you are adding text fields, setting up checkboxes, or adjusting form layouts, WPS PDF makes document manipulation simple and intuitive.
- 1. Open your PDF document: Launch WPS Office and open the PDF file you wish to edit.
- 2. Access form tools: Navigate to the 'Form' tab located in the top ribbon menu to access interactive field options.
- 3. Adjust field placement: Click on any existing form field to manually drag, drop, and resize its boundaries without needing complex code.
- 4. Save the interactive PDF: Once your layout is adjusted, save the document to preserve the form's interactive properties.

Frequently Asked Questions
What exactly does the rect property array represent in a PDF form?
The rect property array contains four numerical values structured as [left, top, right, bottom]. These points define the precise coordinates of the upper-left and lower-right corners of the field's bounding box on the PDF page.
Can I hide a PDF form field instead of moving it?
Yes. If your goal is to make a field disappear based on a selection, you can manipulate its display property instead of its rect property by using: this.getField('TargetField').display = display.hidden;
Where can I find the exact coordinates to use in my rect array?
You can find a field's exact coordinates by placing it in the desired location, opening the JavaScript debugging console in your PDF editor, and running: console.println(this.getField('TargetField').rect); to output the coordinate values.




