Fix Acrobat Form Field Visibility Script Using Wrong Dropdown Value
Question details
A JavaScript visibility condition in a PDF form works in reverse or uses an outdated dropdown value during validation, causing fields to show or hide unexpectedly.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing a custom JavaScript validation script to control the visibility of a secondary field based on a dropdown menu selection.
- Observed behavior
- The visibility script uses the previous dropdown value instead of the newly selected one, causing the logic to behave oppositely to what is expected.
Ensure you have access to the form editing mode and the JavaScript console in your PDF editor to test the script execution.
Use event.value and Commit the Selected Value Immediately
This solution fixes the timing issue during the validation event by forcing the script to read the newly selected value before the validation process is finalized.
During a dropdown's validation event, the field's standard value property may still contain the previous value because the validation has not yet finished. By using 'event.value' in your JavaScript, you can read the newly selected option. Additionally, forcing the field to commit the value immediately ensures your visibility logic triggers without requiring the user to click away from the field.
Open the PDF form in Edit mode. Right-click the dropdown field you want to use as the trigger, select 'Properties', and navigate to the 'Options' tab. Check the box labeled 'Commit selected value immediately'.
Switch to the 'Validate' tab within the dropdown field's Properties window and select 'Run custom validation script'. Click 'Edit' to modify your JavaScript.
Modify your conditional logic to reference 'event.value' instead of the field's standard value. For example: if (event.value == "CStSq") { this.getField("fdtime").display = display.hidden; } else { this.getField("fdtime").display = display.visible; }
Save the script, close the Properties window, and exit form editing mode. Select a new option from the dropdown menu to verify that the target field hides or shows correctly.

Create and Manage PDF Forms with WPS PDF
WPS Office includes a comprehensive PDF editor that makes it easy to fill, edit, and manage interactive PDF forms. Enjoy a lightweight interface without complex scripting issues.
- 1. Open your PDF in WPS Office: Launch WPS Office and click on 'PDF Edit' to load your interactive PDF document.
- 2. Access form controls: Navigate to the 'Form' tab on the top ribbon to access interactive form tools.
- 3. Edit or fill fields: Use the provided tools to insert or modify dropdowns, text fields, and checkboxes as needed.
- 4. Save your document: Once your form is set up or filled out, save and export the fully compatible PDF document.

Frequently Asked Questions
Why does my Acrobat JavaScript use the previous dropdown value instead of the new one?
During a validation event, the field's main value property has not yet been updated. You must use 'event.value' to reference the newly selected item before the validation phase is fully committed.
What does 'Commit selected value immediately' do in PDF forms?
This option forces the PDF viewer to trigger formatting, calculation, and validation events the exact moment a user selects a dropdown item, rather than waiting for the field to lose focus.
How do I hide a text field based on a dropdown selection in a PDF?
You can add a custom validation script to the dropdown field. Use an 'if' statement checking 'event.value' and set the target field's display property to 'display.hidden' or 'display.visible'.




