Skip to main content
Known Participant
February 12, 2019
Answered

Enforce a field to be required when certain text is inputted into another field.

  • February 12, 2019
  • 1 reply
  • 817 views

I am trying to prompt Field B to become required only when Field A contains specific text such as "Apples", "Oranges", and "Bananas".

I have tried this code in the Custom Calculation Script of Field B:

if (this.getField("A").value=="Apples"){event.target.required=true}

else

{event.target.required=false}

Which works, but it won't work when Field A has other words like "Oranges" and "Bananas" with this script:

if (this.getField("Name").value=="Apples", "Oranges", "Bananas"){event.target.required=true}

else

{event.target.required=false}

How can I prompt field B to be required if field A has any of these words in it?

This topic has been closed for replies.
Correct answer try67

The same as before... This is the whole script:

var v = this.getField("Name").value;

if (v=="Apples" || v=="Oranges" || v=="Bananas")

{event.target.required=true}

else

{event.target.required=false}

1 reply

try67
Community Expert
Community Expert
February 12, 2019

It will work if you use the correct syntax. One option of doing it is like this:

var v = this.getField("Name").value;

if (v=="Apples" || v=="Oranges" || v=="Bananas") ...

Known Participant
February 12, 2019

What would the rest of the script be? I tried to add the

else

{event.target.required=false}

but got a syntax error.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 12, 2019

The same as before... This is the whole script:

var v = this.getField("Name").value;

if (v=="Apples" || v=="Oranges" || v=="Bananas")

{event.target.required=true}

else

{event.target.required=false}