How to Require a Comment When a PDF Form Answer is Yes
Question details
The user needs to configure a PDF form so that selecting 'Yes' in a drop-down field dynamically displays a required comment text field, while selecting 'No' hides it.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Creating advanced PDF forms with conditional logic for user inputs.
- Observed behavior
- The goal is to have the comment field hidden and optional by default, becoming visible and mandatory only when 'Yes' is selected.
Ensure you have a PDF editor that supports advanced form creation and JavaScript editing, such as WPS PDF or Adobe Acrobat. Basic familiarity with PDF field properties is recommended.
Use JavaScript to Conditionally Show and Require the Field
Add custom JavaScript to the drop-down's Validate or Calculate tab to control the visibility and required status of the comment field.
Interactive PDF forms can utilize JavaScript to create dynamic behaviors. By binding a script to a drop-down menu, you can listen for specific selections and modify the properties of other fields in real time.
Insert a Drop-down field onto your PDF page and add 'Yes' and 'No' as the export values. Next, insert a Text field nearby where the user will enter their comment.
Right-click the comment Text field and select Properties. In the General tab, set the default form field visibility to 'Hidden'.
Right-click your Drop-down field and select Properties. Navigate to the 'Validate' or 'Calculate' tab, and choose the option to 'Run custom validation script'.
Enter the script to check the event value. For example: if (event.value == 'Yes') { this.getField('CommentField').display = display.visible; this.getField('CommentField').required = true; } else { this.getField('CommentField').display = display.hidden; this.getField('CommentField').required = false; }
Save your PDF document and test the drop-down interaction to ensure the comment field appears and successfully prevents submission when left empty.

Create and Manage Interactive PDF Forms with WPS Office
WPS PDF provides a comprehensive suite of tools for creating interactive PDF forms, adding advanced text fields, and managing complex document properties with ease.
- 1. Launch WPS PDF: Open WPS Office and launch the WPS PDF application on your computer.
- 2. Open Your Document: Open an existing PDF document or create a new blank PDF to start building your form.
- 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive field tools.
- 4. Insert Interactive Fields: Click to insert Drop-down menus, Text fields, and Checkboxes exactly where you need them on the page.
- 5. Configure Properties: Right-click any inserted field, select 'Properties', and customize its options, actions, and validation settings.

Frequently Asked Questions
Why doesn't the comment field appear when I open the PDF in my web browser?
Many web browser PDF viewers (like Google Chrome, Safari, or Microsoft Edge) have limited or no support for PDF JavaScript execution. To ensure conditional fields work properly, users should open the form in a dedicated desktop PDF reader like WPS PDF or Adobe Acrobat.
What is the exact JavaScript syntax to show and hide a field in a PDF?
In PDF JavaScript, you can use `this.getField("FieldName").display = display.visible;` to show the field, and `display.hidden` to hide it. Make sure the 'FieldName' exactly matches the name of your target text field.
Can I require a comment for multiple drop-down fields in the same document?
Yes, you can apply similar conditional validation scripts to multiple drop-down fields. Just ensure that each script references the correct text field name so that each drop-down triggers its own specific comment box.




