Skip to main content
Participant
April 6, 2022
Question

I have read all sorts of how to on populating a drop down list

  • April 6, 2022
  • 3 replies
  • 1425 views

Why in gods name do I need a button to populate a drop down from a list this should not be complicated........All I want to do is populate a the drop with a list of names and values I do not want to push a button....to load said values, I just want to use Java to point at the dang list so I do not have type each and everyone over.  If anyone can help me it would be appreciated. I would like to if possible to simply put a script into the custom calc script box for the drop down list under the calculate tab if possible or be told I cannot do it. Currently I have an excel file with the values I would like in the drop down list. I would think but do not know that an array and a getfield or the like would work.

Thank you ahead of time LOL! 

This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
April 7, 2022

Just execute the code from the JS Console.

try67
Community Expert
Community Expert
April 7, 2022

The basic code is this:

 

this.getField("Dropdown1").setItems(["Default item", "Item 1", "Item 2", "Item 3"]);

 

If you want to import a list from an Excel file you can use this (paid-for) tool I've created:

https://www.try67.com/tool/acrobat-import-items-from-a-text-file-to-a-combo-box-or-list-field

 

Participant
April 7, 2022

Thank you I will forward this to my home computer and see if I can learn this... Unfortunately the govy folks get all excited about links etc. Again Thank you I will get busy...

 

bebarth
Community Expert
Community Expert
April 7, 2022

Hi,

You don't need a button to populate a dropdown.

You must place a custom keystroke script with the "willcommit" and "changeEx" event properties as in my attached example.

 

if(!event.willCommit) {
	if (event.changeEx!=0) {
		for (var i=1; i<cells.length; i++) {
			if (event.changeEx==cells[i][1]) {
				this.getField("name").value=cells[i][0]+" "+cells[i][1];
				...
				break;
			}
		}
		
	} else {
		this.getField("name").value="";
		...
	}
}

 

The script to retrieve the data from the spreadsheet is at document level, so if you modify the spreadsheet, you will have to save, close then re-open pdf file.

Hope that will help you!

@+

Bernd Alheit
Community Expert
Community Expert
April 6, 2022

Use Javascript for this. You can't use Java in Adobe Acrobat.