Skip to main content
Participant
May 19, 2025
Answered

Keystroke Script dropdown menu - with Line Break

  • May 19, 2025
  • 1 reply
  • 1290 views

I Have a form I am building that I would like to indiate a multi line address to populate.

 

I have read a few forums but I am not clear where the various texts should go. Should they be in 2 separate boxes? (selection box directing to a second box?) Screen shots might help because im having trouble visualizing it. 

 

Right now I have 1 Dropdown box. In this box I would like to list several USA address options with the line break instead of 1 long unreadable line. 

 

add1: 

Toll West

450 - 400 Westmont Dr.

San Pedro, CA 90731 USA 

 

add2: 

Toll Ecomm

450 - 400 Westmont Dr.

San Pedro, CA 90731 USA 

 

add3: 

Vertex

1127 Derwent Way

Delta, BC V3M 5R4

 

add4:

California Port

1 Water St

Los Angeles CA 90731

 

Can somone help?

Correct answer try67

Watch this video on using the console window. 

https://www.pdfscripting.com/public/images/video/AcroJSIntro/AcroJSIntro_ConsoleWindow.cfm

 

And here's a re-write of the script, formatted in such a way that it should be easy to add new items to the list. 

var aItems = [
        "Toll West\n450 - 400 Westmont Dr.\nSan Pedro, CA 90731 USA",
        "Toll Ecomm\n450 - 400 Westmont Dr.\nSan Pedro, CA 90731 USA"
];

this.getField("AddressSelection").setItems(aItems);

 

Notice that each dropdown list entry is on a separate line, each line ends with a comma (except for the last one), and lines within an entry are separated with "\n", which in computer lingo is a "newline".    

 

 


Here's a sample file with the field and the multi-line items. You can copy the field directly from this file to yours.

1 reply

Thom Parker
Community Expert
Community Expert
May 19, 2025

The only way to create multi-line entries in a dropdown is to add the entries with a script. 

For example:

 

var aItems = ["Toll West\n450 - 400 Westmont Dr.\nSan Pedro, CA 90731 USA","Toll Ecomm\n450 - 400 Westmont Dr.\nSan Pedro, CA 90731 USA"];

this.getField("AddressSelection").setItems(aItems);

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
jb_1205Author
Participant
May 19, 2025

Hi Thom, thank you. yes I knew a script was needed but im very novice in Java..

Where would I enter that script? In the Keystroke script area? If so would I need any instructions before/after?

 

Also (sorry) what do I list in the dropdown Properties?

sorry so many questions so much appreciation in advance for the help!!

try67
Community Expert
Community Expert
May 19, 2025

Since you only need to run it once, use the Console. It doesn't need to be a part of the script.

And the settings don't matter, since this is an undocumented feature. I would be careful using it, though. If the number of lines is not the same in all items, it will display badly. There's also no way of knowing how it would display in non-Adobe applications or on mobile devices. In short, this is not a very good idea, IMO.