Skip to main content
M.Hasanin
Inspiring
November 24, 2017
Answered

Dynamic DropDown List Add - Delete items

  • November 24, 2017
  • 1 reply
  • 2722 views

Hi Great Developers...

Actually I Started building form (Acrobat Pro DC)  and adding Drop down list and i need to dynamically let the user to add list of emails manually so i insert (Add Button) and (Delete Button) to Add items or delete items to list, for the Adding items Button i wrote the following  (my drop down list name is "EmailList" :

Add Button JavaScript  (not working) :

var oFld = this.getField("EmailList");

var cEntry = oFld.getItemAt(oFld.currentValueIndices,false);

oFld.insertItemAt(cEntry , "s", 0);

and for Delete items Button JavaScript (working code) :

var f = this.getField("EmailList");

f.deleteItemAt(f.currentValueIndices);

now the problem is the Add Button JavaScript is not Working! , please help me if it can be done, thanks in advance

This topic has been closed for replies.
Correct answer M.Hasanin

Thank you for your reply, i succeed in modifying the code so it becomes :

for Adding to dropdown menu from text field it will be :

//Add current email to DropDown list

var emailvalue = this.getField("emailbyuser").value;

var f = this.getField("EmailList");

f.insertItemAt(emailvalue , "", 0);

and for deleting the selected value from dropdown menu it will be :

//Delete current selected value from emaillist

var f = this.getField("EmailList");

f.deleteItemAt(f.currentValueIndices);

1 reply

Thom Parker
Community Expert
Community Expert
November 24, 2017

You're add script isn't adding anything new to the list. It looks like it is trying to move an existing item to the top of the list.

Here's an article that includes a sample file with a button for adding an item to a list, from another list. In your case you might want this to be from a form field, but the script will be almost exactly the same.

https://acrobatusers.com/tutorials/list_and_combo_in_lc

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
M.Hasanin
M.HasaninAuthorCorrect answer
Inspiring
November 25, 2017

Thank you for your reply, i succeed in modifying the code so it becomes :

for Adding to dropdown menu from text field it will be :

//Add current email to DropDown list

var emailvalue = this.getField("emailbyuser").value;

var f = this.getField("EmailList");

f.insertItemAt(emailvalue , "", 0);

and for deleting the selected value from dropdown menu it will be :

//Delete current selected value from emaillist

var f = this.getField("EmailList");

f.deleteItemAt(f.currentValueIndices);

Mohammad Hasanin