PDF Editing Issues

How to Require a Comment When a PDF Form Answer is Yes

Phi Hung VoPhi Hung Vo Nov 3, 2026 869 views

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.

How to Require a Comment When a PDF Form Answer is Yes
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.
Before you start

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.

Solution 1Recommended

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.

1
Create the Form Fields

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.

2
Set Default Visibility

Right-click the comment Text field and select Properties. In the General tab, set the default form field visibility to 'Hidden'.

3
Access Drop-down Validation

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'.

4
Write the JavaScript Code

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; }

5
Test Your Form

Save your PDF document and test the drop-down interaction to ensure the comment field appears and successfully prevents submission when left empty.

Use JavaScript to Conditionally Show and Require the Field
Testing PDF Forms: Always test your form in a dedicated desktop PDF application. Browser-based PDF viewers (like Chrome or Edge) may not support all Acrobat JavaScript features.
Advanced PDF Form Editing

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. 1. Launch WPS PDF: Open WPS Office and launch the WPS PDF application on your computer.
  2. 2. Open Your Document: Open an existing PDF document or create a new blank PDF to start building your form.
  3. 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive field tools.
  4. 4. Insert Interactive Fields: Click to insert Drop-down menus, Text fields, and Checkboxes exactly where you need them on the page.
  5. 5. Configure Properties: Right-click any inserted field, select 'Properties', and customize its options, actions, and validation settings.
Easily create and customize dynamic PDF formsFully compatible with standard PDF formats and Adobe Acrobat form logicInsert and manage interactive elements like drop-downs, text boxes, and checkboxesLightweight, fast, and feature-rich interface for professional editing
microsoft office alternative - wps office

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.