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

PDF Form: Change Value of Items in Dropdown via Scrpit

New Here ,
Sep 23, 2020 Sep 23, 2020

Hi,

I have the following Problem. I wrote a script, that creates a dropdown. The script looks like this:

var aOptions = [

"Apple",

"Strawberry",

"Kiwi",

];

this.getField("Fruit").setItems(aOptions);

How can I change the script, so that the Items I created get another export Value. For example:

Item = Apple; Export Value = A

 

I hope you can understand my problem. Best Regards

TOPICS
Acrobat SDK and JavaScript
3.7K
Translate
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 2 Correct answers

Community Expert , Sep 23, 2020 Sep 23, 2020

Like this:

 

var aOptions = [

["Apple", "A"],

["Strawberry", "S"],

["Kiwi", "K"]

];

Translate
Community Expert , Sep 23, 2020 Sep 23, 2020

First of all, if it's the calculation script for "Short" then it should be:

 

event.value = getField("Fruit").value;

 

If you want to then change it you can add the following after that line:

 

if (event.value=="Apple") event.value = "A";

if (event.value=="Kiwi") event.value = "K";

 

etc.

Translate
Community Expert ,
Sep 23, 2020 Sep 23, 2020

Like this:

 

var aOptions = [

["Apple", "A"],

["Strawberry", "S"],

["Kiwi", "K"]

];

Translate
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 ,
Sep 23, 2020 Sep 23, 2020

Use the setItems() method like this:

 

var f = this.getField("Fruit");
f.setItems([["Apple", "A"],["Starwberry", "S"],
["Kiwi", "K"]]);

 

Translate
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 ,
Sep 23, 2020 Sep 23, 2020

Thank you very much that is working really good.

I have another Problem: I have a Textbox, that is linked to the value of my Dropdown List. 

But this only works, when I select from the dropdown. If I type in Apple (into the Dropdown), in my Textbox there also appears Apple and not A. 

How can I modify my Script, so it works when I select it via Dropdown but also when I write it in?

Translate
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 ,
Sep 23, 2020 Sep 23, 2020

You can't, unless you hard-code into the script of the text box to treat "Apple" as "A", "Kiwi" as "K", etc.

When the user enters a value manually to a drop-down there's no separate export value, only what they entered.

Translate
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 ,
Sep 23, 2020 Sep 23, 2020

Ok and how would that work?

My script for the textbox is looking like this:

this.getField("Short").value = getField("Fruit").value

 

Can I use a simple set() Function? Sorry, I´m really new to coding..

Best Regards

Translate
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 ,
Sep 23, 2020 Sep 23, 2020

First of all, if it's the calculation script for "Short" then it should be:

 

event.value = getField("Fruit").value;

 

If you want to then change it you can add the following after that line:

 

if (event.value=="Apple") event.value = "A";

if (event.value=="Kiwi") event.value = "K";

 

etc.

Translate
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 ,
Sep 23, 2020 Sep 23, 2020

Thank you again.

Now I have a more general kind of question:

if my script is too long for adobe; is there a way I can still integrate it into my File?

Translate
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 ,
Sep 23, 2020 Sep 23, 2020
LATEST

You can use an external editor. Look under Edit - Preferences - JavaScript.

Translate
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