Highlighted

PDF Form: Change Value of Items in Dropdown via Scrpit

New Here ,
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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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.

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

182

Likes

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

PDF Form: Change Value of Items in Dropdown via Scrpit

New Here ,
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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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.

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

183

Likes

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
Sep 23, 2020 0
Most Valuable Participant ,
Sep 23, 2020

Copy link to clipboard

Copied

Like this:

 

var aOptions = [

["Apple", "A"],

["Strawberry", "S"],

["Kiwi", "K"]

];

Likes

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
Reply
Loading...
Sep 23, 2020 0
Adobe Community Professional ,
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"]]);

 

Likes

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
Reply
Loading...
Sep 23, 2020 0
New Here ,
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?

Likes

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
Reply
Loading...
Sep 23, 2020 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Sep 23, 2020 0
New Here ,
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

Likes

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
Reply
Loading...
Sep 23, 2020 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Sep 23, 2020 0
New Here ,
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?

Likes

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
Reply
Loading...
Sep 23, 2020 0
try67 LATEST
Most Valuable Participant ,
Sep 23, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Sep 23, 2020 0