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

Multiple drop down menu troubles

mhgraves
Registered: Oct 13 2009
Posts: 5
Answered

Hello all.

I'm trying to make a form that has certain subforms appear depending on two choices made in the drop down menus. Looking through these forums and others I came up with what I thought would work...and it does for the most part. When I choose an option in the first drop down menu the second is populated as I want. When I choose an option in the second drop down menu the proper subforms are displayed below, but the first drop down menu loses its value.

I'm using switch (xfa.event.newText) for both drop down menus and I think that has something to do with it, but I cannot figure it out. The file is linked below. Any help would be greatly appreciated.

Also, the full version of this form could possibly have ~300 subforms by the time I'm finished with it. Is there a more efficient way to script this?

Thanks,
Mark

[url]https://share.acrobat.com/adc/document.do?docid=340cc02b-88e4-485b-9d03-fc9fd269099a[/url]

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

I changed your form a bit.

1. For populating drop down lists, it's more handy to use document variables (File > Form Properties > Variables).
A form variable can contain an array with all the values you need.
For the first drop down list "Choice1" you can add a form variable named "Choice_1" and this code for the array.
new Array("Company A","Company B","Company C");

To populate the values to the drop down list you use a small script in the enter event of it.
var arrayItems = eval(Choice_1.value);for (var i=0; i < arrayItems.length; i++) {this.addItem(arrayItems[i]);}

Now every time you enter the drop down, it's populated with the values of the form variable "Choice_1".

2. For the second drop down list "Choice 2" you also can create form variables, one for every value of the 1st drop down list.
Form variable "Company_A":
new Array("Service Group A","Service Group B","Service Group C","Display All");

Form variable "Company_B":
new Array("Item Group A","Item Group B","Item Group C");

Form variable "Company_C":
new Array("Misc Group A","Misc Group B");

To populate the values depending on the choice made on the 1st drop down list just put this script into the enter event of the 2nd drop down list.
if (xfa.resolveNode("form1.#subform.Choice1").rawValue == "Company A"){xfa.resolveNode("form1.#subform.Choice2").clearItems();var arrayItems = eval(Company_A.value);for (var i=0; i < arrayItems.length; i++){this.addItem(arrayItems[i]);}}if (xfa.resolveNode("form1.#subform.Choice1").rawValue == "Company B"){xfa.resolveNode("form1.#subform.Choice2").clearItems();var arrayItems = eval(Company_B.value);for (var i=0; i < arrayItems.length; i++){this.addItem(arrayItems[i]);}}if (xfa.resolveNode("form1.#subform.Choice1").rawValue == "Company C"){xfa.resolveNode("form1.#subform.Choice2").clearItems();var arrayItems = eval(Company_C.value);for (var i=0; i < arrayItems.length; i++){this.addItem(arrayItems[i]);}}

3. To control your subforms visibility it's way better to control them by a script within the subforms itself.
Therefore you wrap all subforms that should dis/appear at once into one subform and then you place a script into the calculate event of this subform.
With this method you have a much better overview and not so extremely long switch-case-scripts.
if (xfa.resolveNode("form1.#subform.Choice2").rawValue == "Item Group A"){this.presence = "visible";}else{this.presence = "hidden";}

https://share.acrobat.com/adc/document.do?docid=24c86a3f-6385-4ea2-8da4-c6d4b692eb9d

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

mhgraves
Registered: Oct 13 2009
Posts: 5
Thank you very much for the reply and it works perfectly!
KDCS
Registered: Sep 30 2009
Posts: 36
Is there a way to add a .rawValue to each of the items in the pull down menus that can be totaled.
mhgraves
Registered: Oct 13 2009
Posts: 5
I did find one little thing with the form that wasn't quite working right but managed to fix it. I thought I'd post it for anyone else dealing with a similar problem.

When the "Choice 1" box was selected multiple times, the array was created again and again without clearing the initial array. Also, after selecting an option in the "Choice 2" box and then changing the "Choice 1" box, the "Choice 2" selection did not reset. Below is what I added to the code in the Choice1 drop down list:

xfa.resolveNode("form1.#subform.Choice1").clearItems();xfa.resolveNode("form1.#subform.Choice2").clearItems();var arrayItems = eval(Choice_1.value);for (var i=0; i < arrayItems.length; i++) {this.addItem(arrayItems[i]);}
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Right! It's better to clear all the values of the dropdown first, to avoid repeating of the same values.

I use the following code in the enter event of each dropdown box in front of the code to populate it.
this.clearItems();...

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

DianaL
Registered: Nov 17 2009
Posts: 80
Hi,

I have a similar problem to solve and i tried to code this way because i have two dropdown lists and a populating group. it works everything well, but the only problem is. I cant select like in this case in the dropdown list choice2 several options, but only one item.
How can i solve this problem?

Thank you very much!

Diana
libraboy
Registered: Dec 14 2007
Posts: 94
Hi Radzmar,
Can you please help me on how to put dropdown with showing subforms?

example: If I select 2 in dropdown, two dynamic form will show. Is only 1 then only 1 will show.

Please help me or anyone knows how to.

Thanks