Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Pre-fill a text field based on drop down menu selection

Avatar

Level 1

Greetings everyone!

I've been tasked with creating a fillable form my workplace, and unfortunately, LiveCycle (honestly, coding / scripting in general) is not my strong suit.

This forum has been a huge asset already, with previous suggestions being of great help.  However, I think I've gotten as far as I can without asking for some assistance.

My form already has drop down menus that are populated dependent upon selections made from a prior drop down menu.  I'm trying to find the option to attach a file to use as an example, but until I do (or until I edit in a link) I'll try a quick description.  The form is regarding Alarm System information, and the current fields I have pertain to Manufacturers and Models of alarm systems.  A quick comparison would be cars.  Selecting "Honda" in the first drop down would populate the second drop down with "Accord, Element, etc." as individual options.

What I've been tasked with adding now is Emergency Authority information for each area.  This means that the first drop down would be the type of authority (Fire, Police, etc.), the second drop down would be populated by cities based on the first choice, and the third will (hopefully) be a text field pre filled with the phone number.

Okay, I still can't figure out how to attach or upload a file here, so I've uploaded it to dropbox:

http://db.tt/a7SAVEic

(You'll need to click the "Add" button button next to "Authority Numbers" to expand the area).

I had come across this (http://forums.adobe.com/message/1334821#1334821) as a potential solution, but I can't seem to figure out how to implement it correctly.

If anyone is able to give me some guidance, I'd really appreciate it!

- Dave

4 Replies

Avatar

Level 10

Hi Dave,

When dealing with dropdowns the best event to use is the preOpen event. This means that there wouldn't be any script in the first dropdown.

Then in the second dropdown you would have a relative simple script that would look back at the user's selection in the first dropdown and then populate the display items in the second dropdown.

See examples here:

http://assure.ly/jcTahK

http://assure.ly/gcXx03

http://assure.ly/fYCuQ2

When adding an item to a dropdown, you can specify both the display item (what the user's sees) and the bound value (the value of the dropdown that is associated with the user's selection).

So,

this.additem("Clonmel", "(052) 1234567");

This would add a city "Clonmel" to the dropdown and the value of the dropdown would be "(052) 1234567", if the user selected Clonmel.

The textfield can then be given the same name as the dropdown and its binding set to Global (see the object > Binding palette when the textfield is selected).

Hope that helps,

Niall

Avatar

Level 1

Hi Niall,

Thanks very much for the quick and helpful response.  This looks to be exactly what I need!

I had been questioning my implemenation of what I already had in use, and this looks to be much more streamlined.

Thanks again!

- Dave

Avatar

Former Community Member

Is there a way to pre-select the first choice from the second drop down list, based on the first drop down list selection.  For the "Null pattern for dropdown" example, if a user select Gender  = Male, Relationship would default to Father, but the user can still use the dropdown list select Relationship equal something else like "Son" or "Uncle".

Thanks,

Anh

Avatar

Level 10

Hi,

you can use the setItemState method to preselect a value in a dropdown list.

Select the first value (its index = 0) of drop down list 2 if "Male" is selected, else the second value.

if ($event.change eq "Male") then

          DDL2.setItemState(0, 1)

elseif ($event.change eq "Female") then

          DDL2.setItemState(1, 1)

endif