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

Populate Field Based on Multiple Drop-Down Selections

Community Beginner ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Hi all,

I am trying to get fields to auto-populate based on selections from multiple drop down boxes. I currently have used things to auto-populate based off of a single drop down selection using the below script:

  • var f = this.getField("Dropdown1"); 
  • if (f.valueAsString=="Option 1") event.value = "Text 1"
  • else if (f.valueAsString=="Option 2") event.value = "Text 2"
  • else if (f.valueAsString=="Option 3") event.value = "Text 3"
  • else event.value = "Default text"

However I want to set it up so that certain options come up if selections from multiple fields are true. Example would be:

Drop-Down 1; selection 1 and drop-down 2; selection 1 gives you response 1

Drop-Down 1; selection 2 and drop-down 2; selection 1 gives you response 2

Drop-Down 1; selection 1 and drop-down 2; selection 2 gives you response 3

Drop-Down 1; selection 2 and drop-down 2; selection 2 gives you response 4

Is this possible?

Thanks.

TOPICS
Acrobat SDK and JavaScript

Views

695

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 , May 09, 2018 May 09, 2018

So, this looks like you are using a calculation script on the target field?  All you need to do is make some simple modifications the script.

var f = this.getField("Dropdown1");

var g = this.getField("Dropdown2");

if ((f.valueAsString=="Option 1") && (g.valueAsString == "Choice1")) event.value = "Text 1";

else if ((f.valueAsString=="Option 2") && (g.valueAsString == "Choice2")) event.value = "Text 2";

else if ((f.valueAsString=="Option 3") && (g.valueAsString == "Choice3"))  event.value = "Text 3

...

Votes

Translate

Translate
Community Expert ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

So, this looks like you are using a calculation script on the target field?  All you need to do is make some simple modifications the script.

var f = this.getField("Dropdown1");

var g = this.getField("Dropdown2");

if ((f.valueAsString=="Option 1") && (g.valueAsString == "Choice1")) event.value = "Text 1";

else if ((f.valueAsString=="Option 2") && (g.valueAsString == "Choice2")) event.value = "Text 2";

else if ((f.valueAsString=="Option 3") && (g.valueAsString == "Choice3"))  event.value = "Text 3";

else event.value = "Default text";

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Awesome, thanks for the quick response. One other question, is it possible to maybe only program some of the options, but have it display a default text if none of the rules apply? Meaning if I do the option 1, choice 1, I get text 1, so on and so forth for the specific messages I need for certain pairings, but for pairings that don't matter it can just go to a default text?

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

LATEST

Please disregard. LOL

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