How to Prevent Duplicate Selections in PDF Drop-Down Lists
Question details
The user wants to prevent the same value from being selected across several drop-down fields in a PDF form without having to dynamically rebuild the item lists.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form with multiple drop-down menus where each choice must be unique.
- Observed behavior
- Currently, users can select the identical option in multiple drop-down fields. The goal is to detect the duplication, trigger an alert, and reject the duplicated selection automatically.
Ensure you are using a PDF editor that supports advanced form editing and JavaScript execution. Take note of the exact field names for all interconnected drop-down lists in your form before writing the script.
Apply a Custom Validation Script to Form Fields
Add JavaScript validation to subsequent drop-down fields to compare the current selection with previously selected values, automatically rejecting duplicates.
Instead of complex scripts that dynamically delete chosen options from remaining lists, a simpler approach is using validation scripts. The script checks the incoming selection against prior fields. If a match is found, it alerts the user and cancels the input.
Enter the form editing mode in your PDF editor. Right-click the second drop-down field and select 'Properties'.
In the Properties window, click on the 'Validate' tab and select the option to 'Run custom validation script'.
Click 'Edit' and add a JavaScript snippet to compare the current value to the first field. For example: `var field1 = this.getField('Dropdown1').value; if (event.value !== '' && event.value === field1) { ... }`.
Inside the duplicate condition block, trigger an alert using `app.alert('This value is already selected in a previous field.');` and reject the input by setting `event.rc = false;`.
Apply a similar validation script to the third drop-down field, ensuring the script tests the value of both the first and second fields. Repeat this pattern for any remaining fields.

Create and Manage Interactive PDF Forms with WPS PDF
WPS Office provides an intuitive and powerful PDF editor designed to help you create professional, interactive forms. Easily add drop-down lists, customize field properties, and ensure your forms work seamlessly across devices.
- 1. Open the Document: Launch WPS Office and open your PDF file using the WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal all interactive field options.
- 3. Add Drop-Down Lists: Click on 'Drop-down List' and draw the field on your page, then double-click to configure its options and behaviors.
- 4. Save and Distribute: Once your form is configured, save the PDF. Your interactive form is now ready to be filled out by users.

Frequently Asked Questions
Why does the alert pop up, but the drop-down still accepts the duplicate value?
This happens if your script is missing the command `event.rc = false;`. This specific line tells the PDF viewer to reject the user's input. Without it, the viewer shows the warning but continues to accept the selection.
Is it possible to dynamically remove selected items from the drop-down lists instead?
Yes, dynamically rebuilding the item list is possible via advanced JavaScript routines. However, it is significantly more complex because it requires updating the available options of all remaining drop-down fields every time a selection changes. A custom validation script is usually preferred for its simplicity and reliability.
Will these custom validation scripts work on mobile PDF readers?
JavaScript support varies heavily across mobile PDF viewing applications. While it functions perfectly in comprehensive desktop editors like Adobe Acrobat and WPS PDF, some basic mobile readers may ignore custom validation scripts.




