Skip to main content
Santiman21
Known Participant
May 9, 2018 2:49 PM UTC
Answered

Populate Field Based on Multiple Drop-Down Selections

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.

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
May 9, 2018 3:04 PM UTC

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 PDFScriptingUse the Acrobat JavaScript Reference early and often

3 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
May 9, 2018 3:04 PM UTC

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";

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Santiman21
Known Participant
May 9, 2018 3:28 PM UTC

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?

Translate
Santiman21
Known Participant
May 9, 2018 3:34 PM UTC

Please disregard. LOL

Translate