Skip to main content
Participant
September 23, 2020
Answered

PDF Form: Change Value of Items in Dropdown via Scrpit

  • September 23, 2020
  • 2 replies
  • 3661 views

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

This topic has been closed for replies.
Correct answer try67

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


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.

2 replies

ls_rbls
Community Expert
Community Expert
September 23, 2020

Use the setItems() method like this:

 

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

 

Participant
September 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?

try67
Community Expert
Community Expert
September 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.

try67
Community Expert
Community Expert
September 23, 2020

Like this:

 

var aOptions = [

["Apple", "A"],

["Strawberry", "S"],

["Kiwi", "K"]

];