Make an Acrobat Form Field Required Only When the Answer Is Yes
Question details
Make an Explanation field required when a user selects Yes and optional when the user selects No or makes no selection.

- Product
- Adobe Acrobat PDF Forms
- Device & OS
- not provided
- Scenario
- A PDF form asks a Yes or No question and needs an explanation only for a Yes answer.
- Observed behavior
- The Explanation field should be marked as required only when the Yes option is selected.
Open the form in Acrobat and check the Yes/No field name and the export value assigned to Yes. The example uses the field name 4YN and the Yes export value Y; replace them if your form uses different values.
Add a conditional calculation script to the Explanation field
Use Acrobat JavaScript to update the field's required status whenever the Yes/No answer changes.
Open the PDF in Acrobat and select Prepare a form from the tools.
Open the Yes/No field's properties and verify its field name and the export value for Yes. For radio buttons, use the group field name in the script.
Open the Explanation field's properties, select the Calculate tab, and choose Custom calculation script. Click Edit.
In the script editor, enter: event.target.required = this.getField("4YN").valueAsString == "Y"; Replace 4YN and Y with your field name and Yes export value if necessary, then confirm and close the properties.
Select Preview in Prepare a form, choose Yes, and check that Explanation is required. Then choose No or clear the selection and check that it is optional. Test the form's submit action if it has one.

Work with PDFs and Office documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its Microsoft Office format support helps you move existing files into your workflow. Use Acrobat to configure and test the conditional JavaScript described above.

Frequently Asked Questions
What should I change if my Yes option does not use the value Y?
In Prepare a form, check the Yes option's export value in its properties. Replace "Y" in the script with that exact value, including its capitalization.
Does the script require an explanation if no answer is selected?
No. The comparison is true only when the answer field's value is Y, so Explanation is optional for No or no selection. To require an answer to the Yes/No question itself, set that field as required in its properties.
Where do I add the script?
In Acrobat, open Prepare a form, open the Explanation field's properties, and select Calculate > Custom calculation script > Edit.
Why does the required setting not change in another PDF viewer?
The viewer may not support Acrobat JavaScript or may have it disabled. Test the form in Acrobat or Acrobat Reader with JavaScript enabled, and use the form's submit action to check required-field validation.




