Skip to main content
Participant
April 21, 2017
Answered

Javascript - How to populate a text field with a string of text based on the selection of two dropdown lists

  • April 21, 2017
  • 1 reply
  • 1381 views

Greetings. I have looked all over for this solution and am hitting a wall.

I have two dropdown lists on my Adobe Acrobat DC form. Here is the pseudocode I am trying to create into a javascript action:

If (dropdownList1 value == "department1") && (dropdownList2 value == "building1") then textBox value == "Mr. Church"

else

textBox value == " "

Anyone had any luck getting something like this working?

Thanks.

[Moderator moved from non-technical forum Lounge to JavaScript .]

Nancy

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

You almost have the correct script - you just need to convert it to valid JavaScript syntax and to use the correct Acrobat API functions:

var d1 = this.getField("dropdownList1").value;

var d2 = this.getField("dropdownList2").value;

if ((d1 == "department1") && (d2 == "building1"))

{

    event.value = "Mr. Church";

}

else

{

    event.value = "";

}

When you use this as the custom calculation script in your text field, you should see the behavior you described.

1 reply

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
April 21, 2017

You almost have the correct script - you just need to convert it to valid JavaScript syntax and to use the correct Acrobat API functions:

var d1 = this.getField("dropdownList1").value;

var d2 = this.getField("dropdownList2").value;

if ((d1 == "department1") && (d2 == "building1"))

{

    event.value = "Mr. Church";

}

else

{

    event.value = "";

}

When you use this as the custom calculation script in your text field, you should see the behavior you described.

Karl Heinz  Kremer
Community Expert
Community Expert
April 21, 2017

BTW: If you want to learn how JavaScript works, take a look here: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC