How to Resize Acrobat Form Fields with JavaScript Conditions
Question details
The user needs to use JavaScript to dynamically adjust the dimensions of a PDF form field and hide an adjacent price field when a specific text condition is met.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms where the layout needs to adapt automatically based on the text input provided by the user.
- Observed behavior
- The goal state is to have the deficiency field expand and the price field disappear when the word 'Note' is entered, and to restore the original layout when the condition is false.
Ensure you have access to Adobe Acrobat Pro or a PDF editor that supports document-level JavaScript and advanced form field property modifications.
Use the rect Property and Regular Expressions
Implement conditional JavaScript using the Acrobat `rect` property to change dimensions and the `hidden` property to toggle visibility.
In Adobe Acrobat, field sizes and positions are defined by the `rect` property, which requires an array of four coordinates: [left, top, right, bottom]. Common variables like 'x' or 'w' are not valid in Acrobat's JavaScript API. For efficient scripting, define your variables and field numbers outside of the conditional blocks, and use a case-insensitive regular expression to detect trigger words.
Open your PDF document in Adobe Acrobat, navigate to 'Tools', and select 'Prepare Form' to enable form editing.
Right-click the target text field (e.g., the deficiency field) that will trigger the script and select 'Properties'.
Go to the 'Format' or 'Calculate' tab, select 'Custom calculation script' or custom format script, and click 'Edit'.
Write the initial variable declarations to retrieve the field number and price field: var defNumber = event.target.name.slice(-1); var priceFld = this.getField("exteriorElectricalPrice" + defNumber);
Add the conditional block using a regular expression: if (/note/i.test(event.value)) { priceFld.hidden = true; event.target.rect = [event.target.rect[0], event.target.rect[1], event.target.rect[0] + 7.2112 * 72, event.target.rect[3]]; } else { priceFld.hidden = false; }
Close the properties dialog, exit form editing mode, and type 'Note' into the field to verify the script triggers the resizing and hiding properly.

Edit PDFs and Manage Forms Easily with WPS Office
While complex dynamic JavaScript behaviors require advanced coding in Acrobat, WPS Office provides an intuitive, lightweight PDF editor that lets you easily create, fill, and modify standard PDF forms without writing code.
- 1. Launch WPS Office: Open WPS Office and click on 'PDF Edit' from the home dashboard to load your document.
- 2. Access Form Controls: Navigate to the 'Form' tab on the top ribbon to view all available form tools and interactive elements.
- 3. Modify Field Properties: Double-click any existing form field to open the properties panel, where you can easily adjust its appearance, size, and visibility.

Frequently Asked Questions
Why doesn't changing the 'w' or 'x' property resize my Acrobat form field?
Adobe Acrobat's JavaScript API does not recognize 'w' (width) or 'x' for field dimensions. To resize a field, you must manipulate its `rect` property, which takes an array of four coordinate values representing the field's boundaries: [left, top, right, bottom].
How do I make a PDF form field hidden using JavaScript?
You can easily toggle the visibility of a field by altering its `hidden` property. For example, using `this.getField("FieldName").hidden = true;` will hide the field from view.
How do I check if a field contains a specific word regardless of capitalization?
Use a regular expression with the `test()` method and the `i` flag for case insensitivity. For example, `/note/i.test(event.value)` evaluates to true whether the user types 'note', 'Note', or 'NOTE'.
Why is my Acrobat script returning a null value for my target field?
This commonly happens if the field name string is incorrect or if variables are defined inside a conditional statement where they are not properly initialized. Always retrieve your field objects (e.g., using `this.getField()`) before executing your conditional statements.




