Skip to main content
Participant
Mar 18, 2020 7:14 AM UTC
Question

How to add item to drop-down list using javascript?

I added button to my pdf and when I clicked to button, it added a textarea dynamically.

So I want to keep these names on drop-down list but I cannot add item dynamically to drop-down in javascript.

 

I wrote like this;

this.getField("list").setItems(["CustomItem" + count]);

but this code added only one item.

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

Thom Parker
Community Expert
Community Expert
Mar 18, 2020 4:13 PM UTC

Here's an article on how to add and remove items from a list and/or dropdown. And there is a sample file.

https://acrobatusers.com/tutorials/list_and_combo_in_lc/

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
Mar 18, 2020 9:21 AM UTC

You must use a list. Read the items of the dropdown, create a list of this items, and add the new entry. Then use the method setItems with this list.

You can also use the method insertItemAt.

Translate
Participant
Mar 18, 2020 9:29 AM UTC

Thank you.

I thought this way but cannot find anything how can I get this list in JS.

Translate
Bernd Alheit
Community Expert
Community Expert
Mar 18, 2020 9:43 AM UTC

To read the entries you can use the method getItemAt.

Translate
JR Boulay
Community Expert
Community Expert
Mar 18, 2020 9:18 AM UTC

Try this:

this.getField("list").setItems(["CustomItem1" + count, "CustomItem2" + count, "CustomItem3" + count ]);

Translate
Acrobate du PDF, InDesigner et Photoshopographe
Participant
Mar 18, 2020 9:24 AM UTC

Thank you for answer.

 

But I added dynamically. New control is adding when I click to a button.

So I must add a new item to old items.

 

For example first click I want to add new item control1,

second click, add new item control2.

Translate