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

Dropdown Choices

gspaull
Registered: Feb 22 2010
Posts: 2
Answered

Hi There

I was wondering if anyone new a way of using FormCalc to change options in a dropdown based on another selections choice.

i.e. if from dropdown 1, choice 1 is selected, then in dropdown 2 I only want them to be able to select Choice 1 or choice 3 (because choice 2 in the dropdown is not available for choice 1 in dropdown 1).

Is there a way of 'greying out' the option or removing it compeltely using formcalc?

Thanks

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

this is possible.
You can use JavaScript and form variables to populate one dropdown list based on another dropdown lists choice.

First you need to create form variables (File > Form properties > Variables).
They contain an array of values you can select from the dropdown lists.
You need one for the first dropdown list and one for each choice for the second dropdown list.

For dropdown list 1 name it "List1" and put this script into value field.
  1. new Array("AAA",
  2. "BBB",
  3. "CCC");

For dropdown list 2 create 3 variables named "List2_Choice_AAA", "List2_Choice_BBB" and "List2_Choice_CCC".
Everyone then gets a different array (In this example several values from the pool of 111, 222, 333, 444, 555).
  1. new Array("111",
  2. "333",
  3. "444",
  4. "555");

  1. new Array("333",
  2. "444",
  3. "555");

  1. new Array("111",
  2. "222",
  3. "555");

So, now you need to add scripts to the dropdown lists to populate them with the arrays.
For the first dropdown list you use this JS in the enter:event.
  1. if (this.rawValue == null)
  2. {
  3. var arrayItems = eval(List1.value);
  4. for (var i=0; i < arrayItems.length; i++)
  5. {
  6. this.addItem(arrayItems[i]);
  7. }
  8. }

In the second you put.
  1. if (DropDownList1.rawValue == "AAA" && this.rawValue == null)
  2. {
  3. var arrayItems = eval(List2_Choice_AAA.value);
  4. for (var i=0; i < arrayItems.length; i++)
  5. {
  6. this.addItem(arrayItems[i]);
  7. this.setItemState(0,1);
  8. }
  9. }
  10. if (DropDownList1.rawValue == "BBB" && this.rawValue == null)
  11. {
  12. var arrayItems = eval(List2_Choice_BBB.value);
  13. for (var i=0; i < arrayItems.length; i++)
  14. {
  15. this.addItem(arrayItems[i]);
  16. this.setItemState(0,1);
  17. }
  18. }
  19. if (DropDownList1.rawValue == "CCC" && this.rawValue == null)
  20. {
  21. var arrayItems = eval(List2_Choice_CCC.value);
  22. for (var i=0; i < arrayItems.length; i++)
  23. {
  24. this.addItem(arrayItems[i]);
  25. this.setItemState(0,1);
  26. }
  27. }

So now the selection in the second dropdown depends on the first one and populates different array.

Some cosmetics to the behavior of the dropdown list is the final step.
If you already have selected a value in the first dropdown and change this, the second one needs to be cleared before populating with values.
This JA in the change:event does the job.
  1. DropDownList2.rawValue = null;
  2. DropDownList2.clearItems();
  3. DropDownList2.setItemState(0, true);

I know, it looks complicated at first, but it really isn't. ;-)

Sample Form

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

omastroberti
Registered: May 10 2010
Posts: 1
Hi!

I'm wondering if is it possible to do this but with a radiobutton?
Supose I have RB1, if the option "F" is checked, then in a DDM1, the options shoud be populated like this:
DNI
PASS
CE
LE

But, if in the RB1 the selected option is "J", then in the DDM1, the items should be:
SRL
SA
SACI

The code to make the DDM I have found somewhere, but I cant find how to know, wich item in the radiobutton was selected...

Any ideas? Appreciate very much!

Oscar

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Sure you can.

You only need the scripts for the second drop down of my sample above and change them to checks the current value of your radio button group.

if (RadioButtonGroup1.rawValue == "1" && this.rawValue == null){...}

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

realname
Registered: Aug 15 2008
Posts: 93
Hi,
I followed your instructions on here and finally achieved what I was trying to do (THANK YOU, THANK YOU) however, I have one problem.
The values in my dropdown box are dependent on meeting 2 conditions i.e. if box1 == 1 and box2 == 3, then populate the dropdown list with arrayX.

My problem is that if a change is made to either box1 or box2, the dropdown is not clearing the items rather it is adding the next array to the previous.

I placed your solution to change in my dropdown box in the change event however, it is not working.

What am I doing wrong?