How to Show an Alert When PDF Drop-Down Selection Conflicts with Entered Hours
Question details
The user needs to create an Acrobat JavaScript calculation script for a PDF form that triggers a warning alert when a specific drop-down option is selected while the hours field is already filled.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form with conditional logic to prevent data entry conflicts between a drop-down selection and a text field.
- Observed behavior
- A custom validation script is required to dynamically check the status of a text field and trigger an alert popup based on the user's drop-down choice.
Ensure you have access to a PDF editor with form creation and JavaScript capabilities, and write down the exact field names for both your text input and drop-down menu.
Apply a Custom JavaScript Calculation Script to the Drop-Down Field
Use a custom calculation script on the drop-down field to check the text field's value first, and display an alert if there is a conflict.
Instead of placing individual validation scripts on multiple fields, applying a single custom calculation script to the drop-down menu ensures the logic is processed exactly when the user makes a selection. This prevents overlapping validation errors and keeps your form logic clean.
Open your PDF editor, enter Form Editing mode, and remove any existing validation scripts from both the hours text field and the drop-down field to prevent conflicts.
Right-click the drop-down field, select 'Properties', and navigate to the 'Calculate' tab.
Select the 'Custom calculation script' option and click 'Edit'. Enter the following JavaScript code: var regHours = this.getField('RegHrs1'); var f = event.target; if (regHours.value !== '' && f.valueAsString == 'CDO (compressed day off)') { app.alert('Do not enter hours', 0); this.resetForm(['RegHrs1']); }
Click 'OK' to save the script. Exit Form Editing mode and preview the document. Test the logic by entering hours and selecting 'CDO' to verify that the alert pops up and the hours field resets.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides robust PDF editing capabilities, allowing you to quickly create fillable forms, manage field properties, and handle interactive documents effortlessly.
- 1. Open your PDF: Launch WPS Office and open your PDF document to begin editing.
- 2. Enter Form Mode: Navigate to the 'Form' tab on the top ribbon to access interactive field tools.
- 3. Edit Properties: Double-click any form field to adjust its appearance, options, and actions easily.

Frequently Asked Questions
Why is the JavaScript alert not showing up in my PDF?
Ensure that JavaScript is enabled in your PDF viewer's security preferences. Additionally, verify that the field names in your script perfectly match the actual field names in your form, as JavaScript is case-sensitive.
Can I use this script to check multiple text fields at once?
Yes, you can declare additional variables for other fields using 'this.getField()' and expand the if-statement using the logical AND (&&) or OR (||) operators to evaluate multiple conditions before triggering the alert.
How do I clear the conflicting field automatically?
The provided script includes the command 'this.resetForm(['RegHrs1']);'. This automatically clears the designated field whenever the alert is triggered, preventing users from saving conflicting data.




