Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Feb 12, 2019 Feb 12, 2019

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?

TOPICS
Acrobat SDK and JavaScript
668
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 12, 2019 Feb 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}

Translate
Community Expert ,
Feb 12, 2019 Feb 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") ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 12, 2019 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2019 Feb 12, 2019
LATEST

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}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines