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

PDF Form: Change Value of Items in Dropdown via Scrpit

New Here ,
Sep 23, 2020 Sep 23, 2020

Copy link to clipboard

Copied

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

Views

2.3K

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 2 Correct answers

Community Expert , Sep 23, 2020 Sep 23, 2020

Like this:

 

var aOptions = [

["Apple", "A"],

["Strawberry", "S"],

["Kiwi", "K"]

];

Votes

Translate

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.

Votes

Translate

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

Copy link to clipboard

Copied

Like this:

 

var aOptions = [

["Apple", "A"],

["Strawberry", "S"],

["Kiwi", "K"]

];

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

Copy link to clipboard

Copied

Use the setItems() method like this:

 

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

 

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

LATEST

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

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