These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Dynamic drop down menu

powellmi
Registered: Oct 25 2010
Posts: 1

I am trying to create a dropdown menu that has groups, once a certian group is selected a second drop down menu has the people in that group. Can someone point me in the right direction on how to do this? I have been playing with it for weeks now and have gotten nowhere.

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If you want a pop-up drop down menu you can use the Acrobat JavaScript 'app.popupMenu'
  1. var cChoice = app.popUpMenu("Introduction", "-", "Chapter 1",
  2. [ "Chapter 2", "Chapter 2 Start", "Chapter 2 Middle",
  3. ["Chapter 2 End", "The End"]]);
  4. app.alert("You chose the \"" + cChoice + "\" menu item");
If you want to use just a dropdown box that populates a second dropdown box, see Thom Parker's Programming List and Combo fields in Acrobat and LiveCycle forms - Part 1.

George Kaiser

SLDC
Registered: Oct 25 2010
Posts: 70
I've done this by adding code to the Exit event for the first dropdown - a switch/case setup where each option in the first dropdown calls a sequence of secondDropDown.addItem() statements. It'd be cleaner to use setItems() instead of a sequence of addItem(), but I haven't found a way to make that work.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
That is one of the differences between Acrobat and LiveCycle Designer.

George Kaiser

adragton
Registered: Nov 14 2010
Posts: 3
SDLC
Please post sample PDF so that I can see script. --I need multiple dependant dropdowns, and last one then fills in textfield(s).

I have this one in the EXIT, but it works only for one(1)DD.

//Initialize vars
var oUser = "";

//Get the User list into an object
var oTemp = xfa.datasets.data.Root.nodes;

//Loop through the nodes in the oTemp set
for (i=0; i< oTemp.length ; i++)
{
//set the currentElement to the 1st child node
currentElement = oTemp.item(i);
//Check to see if it is a user node
if (currentElement.name == "Row")
{
//It is a user node , assign the nodes to a new object
oUser = oTemp.item(i).nodes
// check to see if the value matches the one we chose in the DD
if (oUser.item(0).value == this.rawValue)
{
//we have a match
//Set the other fields with appropraite values
TextField1.rawValue = oUser.item(1).value;
TextField2.rawValue = oUser.item(2).value;

}
}
}



I've done this by adding code to the Exit event for the first dropdown - a switch/case setup where each option in the first dropdown calls a sequence of secondDropDown.addItem() statements. It'd be cleaner to use setItems() instead of a sequence of addItem(), but I haven't found a way to make that work.

SLDC
Registered: Oct 25 2010
Posts: 70
My first dropdown has elements added manually in Designer, but those could be set in code if necessary, perhaps in the Initialize event. Assume those elements are text strings "Choice 1", "Choice 2", "Choice 3".

Then, in the dropdown's Exit event, I have:

switch(this.rawValue) {
case "Choice 1":
SecondDropDown.clearItems(); // clear out SecondDropDown in case the user has chosen something else first
SecondDropDown.addItem("Item 1","Export Value 1");
SecondDropDown.addItem("Item 2","Export Value 2");
SecondDropDown.addItem("Item 3","Export Value 3");
break;

case "Choice 2":
SecondDropDown.clearItems();
SecondDropDown.addItem("Item 4","Export Value 4");
SecondDropDown.addItem("Item 5","Export Value 5");
SecondDropDown.addItem("Item 6","Export Value 6");
break;

case "Choice 3":
SecondDropDown.clearItems();
SecondDropDown.addItem("Item 7","Export Value 7");
SecondDropDown.addItem("Item 8","Export Value 8");
SecondDropDown.addItem("Item 9","Export Value 9");
break;
}

Labor-intensive, but it works for me. You could as easily have the last dropdown do:

textField1.rawValue = "whatever";

etc.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Because Thom's example use an object element name with the same name as the first drop down, there is not choice to be made, if there is a space or special characters in the name one needs to put the element name between quotes. Thom then uses a array for the value of the element and he can then set the items of the next drop down box selections with the contents of the selected element array. No processing based on the selected name as the first drop down boxes names matches the element names in the data object one for one. The value of each element of the data object are the values needed for the next drop down box.

George Kaiser

joekater
Registered: Dec 22 2010
Posts: 3
Hey,
I have almost the same problem.
Ich habe 2 dropdown Listen, The data are stored in arrays and they are drawn from an XML table.
I have in my XML table:
/*
canada
terrybrazil
simaoUSA
max
*/all countries are in the first drop-down list.
I have done so:
var x = XML(this.getField("XMLField").value);
var countryList = [];
for (i=0; i
joekater
Registered: Dec 22 2010
Posts: 3
Hey,
I have almost the same problem.
Ich habe 2 dropdown Listen, The data are stored in arrays and they are drawn from an XML table.
I have in my XML table:

canada
terrybrazil
simaoUSA
maxall countries are in the first drop-down list.
I have done so:
var x = XML(this.getField("XMLField").value);
var countryList = [];
for (i=0; i
joekater
Registered: Dec 22 2010
Posts: 3
joekater wrote:
Hey,
I have almost the same problem.
Ich habe 2 dropdown Listen, The data are stored in arrays and they are drawn from an XML table.
I have in my XML table:
<Adress><country> canada</country><name> terry</name></Adress><Adress><country> brazil</country><name> simao</name></Adress><Adress><country> USA </country><name> max </name></Adress>
all countries are in the first drop-down list.
I have done so:
var x = XML(this.getField("XMLField").value);
var countryList = [];
for (i=0; i x.adress.country.length() ; i++)
{ countryList.push(x.adress[i].country.toString());}
this.getField("DropDownList").setItems(countryList);

my question is now, how do I get names in the second drop down list that belong to the country?!
Ich hoffe, ihr könnt mir helfen.
many greetings
Joe Kater
PurpleHope
Registered: Jul 28 2011
Posts: 2
That example in which Thom uses an object element with the same name really makes sense. I had the same problem and I had to ask a guy who knows Web Design Los Angeles from, to guide me through it. Even with all this internet you can't know it all. For me it's still very difficult to learn by myself.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Read this article:
http://acrobatusers.com/tutorials/2007/js_list_combo_livecycle/

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script