2
$\begingroup$

I intend to have a first PopupMenu function with a list of parameters {a,b,c}. I want a second PopupMenu list of contents to change according to what's in the first list like so:

  • if the first list has 'a' selected then the second list is {1,2,3},
  • if the first list has b selected then the second list is {4,5,6},
  • if the first list has 'c' selected then the second list is {7,8,9}.

I have tried the following:

Row[{
  PopupMenu[x,{a,b,c},a],
  PopupMenu[y,Piecewise[{{{1,2,3},x==a},{{4,5,6},x==b},{{7,8,9},x==c}}]]
}]

but it is not interpreted the way I intended.

How can I accomplish it?

$\endgroup$
2
$\begingroup$

You forgot about Dynamic here and there.

Row[{
  PopupMenu[Dynamic[x], {a, b, c}, a], 
  Dynamic @ PopupMenu[
     Dynamic[y], 
     Switch[x, a, {1, 2, 3}, b, {4, 5, 6}, c, {7, 8, 9}]
  ]
}]
$\endgroup$
  • $\begingroup$ This makes me so happy. I did tried Dynamic just before your post, but in no way similar to this. $\endgroup$ – useranonis Aug 26 '16 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.