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

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

Community Beginner ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

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

Views

353

Translate

Translate

Report

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}

Votes

Translate

Translate
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

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") ...

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

else

{event.target.required=false}

but got a syntax error.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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}

Votes

Translate

Translate

Report

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