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

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

New Here ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript

Views

1.2K

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 , Apr 21, 2017 Apr 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.

Votes

Translate

Translate
Community Expert ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

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.

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 ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

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

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
New Here ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

OMG you are a lifesaver!!! This is EXACTLY what I was looking for.

Thank you! I am new to the forum, so is there any way to assign you points for this?

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
New Here ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

LATEST

How would you add more conditions to that for more combinations of choices?

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