• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

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

New Here ,
Apr 06, 2022 Apr 06, 2022

Copy link to clipboard

Copied

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! 

TOPICS
JavaScript

Views

120

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2022 Apr 06, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

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="";
		...
	}
}

 

Capture_d’écran_2022-04-07_à_10_22_49.png

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!

@+

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

Just execute the code from the JS Console.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

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...

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

So using this.getField and the .setItems how do I apply the value I want to have the dropdown choice to pass? So you have context I am making a dropdown list with the Plant names and the the related wetland code so for instance I choose Cattail,  I want to pass OBL for Obligate to a textbox.

Again thank you for your patience with me.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

To do that you need a 2D-array, like this:

 

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

LATEST

Perfect! THANKYOU these forums rock!

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines