# Popupmenu: Passing arguments with the menu item functions

**URL:** <https://forum.servoy.com/t/popupmenu-passing-arguments-with-the-menu-item-functions/6317>\
**Category:** Classic Servoy\
**Created:** [August 2, 2006, 4:47pm UTC](https://forum.servoy.com/t/popupmenu-passing-arguments-with-the-menu-item-functions/6317 "2006-08-02T16:47:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rarbuthnot](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rarbuthnot](https://forum.servoy.com/u/rarbuthnot)\
**Post date:** [August 2, 2006, 4:47pm UTC](https://forum.servoy.com/t/popupmenu-passing-arguments-with-the-menu-item-functions/6317/1 "2006-08-02T16:47:13Z")

</div>

Is it possible to pass arguments along with the functions in a popup menu?

If I just do

menu _= plugins.popupmenu.createMenuItem(‘Description’,function(arg))_  
_It will immediately go to function (but pas the argument) when trying to show the menu._  
_Thanks._

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [August 2, 2006, 5:20pm UTC](https://forum.servoy.com/t/popupmenu-passing-arguments-with-the-menu-item-functions/6317/2 "2006-08-02T17:20:07Z")

</div>

Try something like

```auto
var vArgs = new Array('yourArg1', 'yourArg2');
var vMenuItem = plugins.popupmenu.createMenuItem('Description',function);
vMenuItem.methodArguments = vArgs;
menu[i] = vMenuItem;

```

That should work (if not, I mistyped something out of my head)…

---

<div class="post-metadata">

**Author:** ![david](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@david](https://forum.servoy.com/u/david)\
**Post date:** [August 7, 2006, 6:18am UTC](https://forum.servoy.com/t/popupmenu-passing-arguments-with-the-menu-item-functions/6317/3 "2006-08-07T06:18:20Z")

</div>

Another fairly straight forward example. Popup trigger code:

```auto
var menu = new Array(
	plugins.popupmenu.createMenuItem('New customer', LIST_action_control),
	plugins.popupmenu.createMenuItem('Delete customer...', LIST_action_control)
)

//set method arguments to consecutive numbers
var x = 0
while (menu[x])
{
	menu[x].setMethodArguments(x)
	x ++
}

var elem = elements[application.getMethodTriggerElementName()]
if (elem != null)
{
	plugins.popupmenu.showPopupMenu(elem, menu);
}

```

Method called (LIST\_action\_control)

```auto
//set label
switch (arguments[0]) {
	case 0:	
			controller.newRecord(true)
			controller.saveData();
			
			FORM_on_show();
			
			//get focus
			forms.CUST_1_customer_form.elements.fld_name_first.requestFocus()
			
			break
	case 1: 
			var dialogInput = plugins.dialogs.showWarningDialog( 'Warning!', 'Are you sure you want to delete this record?',
				'Yes', 'No')		
	
			if (dialogInput == 'Yes') {
				//delete current record
				controller.deleteRecord();
			}
	
			FORM_on_show();
			
			break			
}

```

---

<div class="post-metadata">

**Author:** ![cbarbal](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@cbarbal](https://forum.servoy.com/u/cbarbal)\
**Post date:** [August 24, 2006, 8:55pm UTC](https://forum.servoy.com/t/popupmenu-passing-arguments-with-the-menu-item-functions/6317/4 "2006-08-24T20:55:56Z")

</div>

I have changed the Popup trigger code so that it works with a separator “-”:

```auto
var menu = new Array(
	plugins.popupmenu.createMenuItem(i18n.getI18NMessage('cbs.lb.facturados'), searchPopup),
	plugins.popupmenu.createMenuItem(i18n.getI18NMessage('cbs.lb.no_facturados'),searchPopup),
	plugins.popupmenu.createMenuItem( '-'),
	plugins.popupmenu.createMenuItem(i18n.getI18NMessage('cbs.lb.mismo_cliente'),searchPopup)
)

//set method arguments to consecutive numbers
var x = 0 
while (menu[x]) 
{ 
	//if separator
	if ( menu[x].text == undefined)
	{
	}
	else
	{
		menu[x].setMethodArguments(x) 
	}
   
   x ++ 
} 

var elem = elements[application.getMethodTriggerElementName()] 
if (elem != null) 
{ 
   plugins.popupmenu.showPopupMenu(elem, menu); 
}

```

Regards

Carles Barbal
