Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Popup menu values

Martins_Migle
Level 2
Level 2

Lets say I have a button that opens a popup menu with 2 levels:

Fruits> Apple

            Banana

            Melon

Vegetables> Carrot

                     Potato

                     Tomato

Is it possible to get both values? I mean, to receive information if fruits or vegetables was selected and also what kind of fruit/vegetable.

Thanks in advance.

1 Accepted Solution
_Bruce_Robertson
Correct answer by
Level 10
Level 10

Hi,

You could use the cReturn property to encode a value that lets you determine both values, such as;

var choice = app.popUpMenuEx(

     {cName: "Fruits",

      oSubMenu: [ {cName: "Apple", cReturn: "Fruit,Apple" }, {cName: "Banana", cReturn: "Fruit,Banana" }, {cName: "Melon", cReturn: "Fruit,Melon" } ]},

     {cName: "Vegetables",

      oSubMenu: [ {cName: "Carrot", cReturn: "Vegetables,Carrot"}, {cName: "Potato", cReturn: "Vegetables,Potato"}, {cName: "Tomato", cReturn: "Vegetables,Tomato"} ]});

if (choice !== null)

{    

    var selection = choice.split(","); 

    app.alert("You selected the \"" + selection[1] + "\" menu item from the \"" + selection[0] + "\"");

}

Not ideal as you are effectively coding up the menu structure twice (and assumes you will never use a comma character in a menu item name).

Regards

Bruce

View solution in original post

2 Replies
_Bruce_Robertson
Correct answer by
Level 10
Level 10

Hi,

You could use the cReturn property to encode a value that lets you determine both values, such as;

var choice = app.popUpMenuEx(

     {cName: "Fruits",

      oSubMenu: [ {cName: "Apple", cReturn: "Fruit,Apple" }, {cName: "Banana", cReturn: "Fruit,Banana" }, {cName: "Melon", cReturn: "Fruit,Melon" } ]},

     {cName: "Vegetables",

      oSubMenu: [ {cName: "Carrot", cReturn: "Vegetables,Carrot"}, {cName: "Potato", cReturn: "Vegetables,Potato"}, {cName: "Tomato", cReturn: "Vegetables,Tomato"} ]});

if (choice !== null)

{    

    var selection = choice.split(","); 

    app.alert("You selected the \"" + selection[1] + "\" menu item from the \"" + selection[0] + "\"");

}

Not ideal as you are effectively coding up the menu structure twice (and assumes you will never use a comma character in a menu item name).

Regards

Bruce

View solution in original post

Martins_Migle
Level 2
Level 2

Thanks Bruce, just what I was looking for.