Conditional fields
Copy link to clipboard
Copied
Looking to make a field required based on the answer to a previous field. I know nothing about Javascript.
I require client to select Married or Single in a dropdown Marital Status field. Based on their selection in the Marital Status field I want to require them to input Spouse name, Spouse mobile and Spouse email if they select Married in the Marital Status field
Copy link to clipboard
Copied
The required parameter of a form field doesn't mean anything unless the form is being submitted. You might consider hiding or graying out the spouse field if "single" is selected.
This code just sets the required parameters. Place it in the Custom Validation script for the "Martial Status" dropdown
var bUseSpouse = (event.value == "Married")
this.getField("Spouse name").required = bUseSpouse;
this.getField("Spouse mobile").required = bUseSpouse;
this.getField("Spouse email").required = bUseSpouse;
Here's an article on hiding and showing fields
https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm?sd=40
Use the Acrobat JavaScript Reference early and often

