These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

addItem

umh3
Registered: May 23 2011
Posts: 15
Answered

I am trying to add an item to a dropdown box using javaScript using the addItem() function. Where should the code dropdownbox2.addItem("Hello"); go if I am working within one dropdown box and am refrencing another box?

My Product Information:
Acrobat Pro 10.0.2, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You need to decide what action will trigger the updating of the second drop down box. In the article Thom Parker pointed you to, the second drop down box was updated when an item in the first drop down box was selected.

George Kaiser

umh3
Registered: May 23 2011
Posts: 15
I am still having trouble with the addItem function. In the code for the second box I have

var a = getField("List2");

if(getField("List1").value == "fruit")
{
this.addItem("HI");
}

app.alert("Hello");



The alert is working, however the box does not contain any items. How do I get the addItem function to actually add HI to the dropdown memu?

Thank you.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
"this" usually refers to the currently opened document.
If you want to add "HI" to List2, then use this:

getField("List2").addItem("HI");

Or in your case you can use:

a.addItem("HI");

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

umh3
Registered: May 23 2011
Posts: 15
It still doesn't seem to work. I keep getting an error saying that b.addItem is not a function.


var a = getField("List1");
var b = getField("List2");

if(a.value == "fruit")
{
b.addItem("banana");
}
if(a.value == "veggie")
{
b.addItem("carrot");
}


I put this code in the custom calulation script in the calculate tab.

Thank you for your help!
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
I should have double-checked this...
There's no such thing as addItem(). You probably want to use insertItemAt().
Check the reference for the full parameters description.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com