How do I conditionally set the required fields on my form based on user answers from a radio button?

I have a form where I am asking for Project Type using radio buttons; The options for the radio buttons are "New Construction" and "Retrofit". If "Retrofit" is selected I want the "Account Number" field set to "required" field, but if "New Construction" is selected I want the "Project Name" field required. I am not familiar with Javascripting but assume this can be done.

Katherine Snyder

1 Answer

I would create a hidden text field and add the following script as a Custom calculation script to this hidden text field:

var v = this.getField("Project Type").value; // change radio button group name as needed

var pn = this.getField("Project Name");
var an = this.getField("Account Number");

pn.required = false;
an.required = false;

if (v == "New Construction") {
    pn.required = true;  
else if (v == "Retrofit") {
    an.required = true;   

enter image description here

I would use the hidden text field to consolidate the scripts in one field and to make both "Project Name" and "Account Number" fields not required if the form is reset and no option is selected.

Almir R V Santos   

Please specify a reason: