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
Like this:
var aOptions = [
["Apple", "A"],
["Strawberry", "S"],
["Kiwi", "K"]
];
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.
Copy link to clipboard
Copied
Like this:
var aOptions = [
["Apple", "A"],
["Strawberry", "S"],
["Kiwi", "K"]
];
Copy link to clipboard
Copied
Use the setItems() method like this:
var f = this.getField("Fruit");
f.setItems([["Apple", "A"],["Starwberry", "S"],
["Kiwi", "K"]]);
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?
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.
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
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.
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?
Copy link to clipboard
Copied
You can use an external editor. Look under Edit - Preferences - JavaScript.