# simple popup code

**URL:** <https://forum.servoy.com/t/simple-popup-code/8723>\
**Category:** Classic Servoy\
**Created:** [February 11, 2008, 11:23pm UTC](https://forum.servoy.com/t/simple-popup-code/8723 "2008-02-11T23:23:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.servoy.com/u/Ron)\
**Post date:** [February 11, 2008, 11:23pm UTC](https://forum.servoy.com/t/simple-popup-code/8723/1 "2008-02-11T23:23:14Z")

</div>

I want to create a very simple popup menu but cannot get it to work.  
I have a button on my form (name= ‘pop’) and a method attached to it.  
This is my code:

var menu = new Array(  
plugins.popupmenu.createMenuItem(‘A’,myMethod),  
plugins.popupmenu.createRadioButtonMenuItem(‘B’,myMethod)  
)

//passing arguments how?

menu[0].setMethodArguments(menu[0])  
menu[1].setMethodArguments(menu[1])

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

Can someone point me in the right direction?  
TIA,  
Ron

---

<div class="post-metadata">

**Author:** ![davidaarong](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@davidaarong](https://forum.servoy.com/u/davidaarong)\
**Post date:** [February 12, 2008, 12:47am UTC](https://forum.servoy.com/t/simple-popup-code/8723/2 "2008-02-12T00:47:04Z")

</div>

You could just use application.showFormInDialog to create your own custom window.

- David

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.servoy.com/u/Ron)\
**Post date:** [February 12, 2008, 7:16am UTC](https://forum.servoy.com/t/simple-popup-code/8723/3 "2008-02-12T07:16:56Z")

</div>

Thanks for your reply David, but I don’t want to create a  
window but do want to use the popup-plugin, as you can see  
in my coding.

Regards,  
Ron

---

<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:** [February 12, 2008, 8:20am UTC](https://forum.servoy.com/t/simple-popup-code/8723/4 "2008-02-12T08:20:22Z")

</div>

showPopupMenu expects an element, you provide an element name. So if you change it like this it should work:

```auto
var elem = forms[application.getMethodTriggerFormName()].elements[application.getMethodTriggerElementName()]

```

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.servoy.com/u/Ron)\
**Post date:** [February 12, 2008, 8:53am UTC](https://forum.servoy.com/t/simple-popup-code/8723/5 "2008-02-12T08:53:43Z")

</div>

Sorry Patrick, I know its my ignorance, but still no success.  
This is my actual code:

var menu = new Array(  
plugins.popupmenu.createMenuItem(‘A’,myMethod),  
plugins.popupmenu.createRadioButtonMenuItem(‘B’,myMethod)  
)

menu[0].setMethodArguments(menu[0])  
menu[1].setMethodArguments(menu[1])

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

---

<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:** [February 12, 2008, 9:47am UTC](https://forum.servoy.com/t/simple-popup-code/8723/6 "2008-02-12T09:47:14Z")

</div>

Your code works for me. Does the element where you want to show the popup have a name (property “name”)?

Where does it fail? Do you get an error? How do your variables look like when you debug through this?

Btw: I don’t understand your assignment of arguments. Why do you want to pass the menu item as argument to the menu item?

Typically, people use the popup like this

```auto
var vMenu = new Array();
var vMenuItem;

vMenuItem = plugins.popupmenu.createMenuItem('A',myMethod);
vMenuItem.methodArguments = ['A', 'otherArgument', 1, new Date()] // whatever...
vMenu[vMenu.length] = vMenuItem;
...

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

```

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.servoy.com/u/Ron)\
**Post date:** [February 12, 2008, 10:45am UTC](https://forum.servoy.com/t/simple-popup-code/8723/7 "2008-02-12T10:45:37Z")

</div>

Hi Patrick,

The error message says: Reference error: can’t find myMethod.

But lets forget my code, I have no special reason with my coding I am  
just trying to popup something, without exacly knowing how things work.  
The Servoy sample has to many bells and wishles for me.  
So basically I just want a very simple piece of code, with 2 menu-items calling a method, that works, thats all.  
From there I want to explore the possibilties myself…  
Thanks.

Ron

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [February 12, 2008, 11:04am UTC](https://forum.servoy.com/t/simple-popup-code/8723/8 "2008-02-12T11:04:38Z")

</div>

create a method: myMethod,  
it gives an error because that method does not exist yet!

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 12, 2008, 11:28am UTC](https://forum.servoy.com/t/simple-popup-code/8723/9 "2008-02-12T11:28:36Z")

</div>

If you just want to popup something and not want any method to be triggered you just pass it a null value like so:

```auto
vMenuItem = plugins.popupmenu.createMenuItem('A',null);

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.servoy.com/u/Ron)\
**Post date:** [February 12, 2008, 11:33am UTC](https://forum.servoy.com/t/simple-popup-code/8723/10 "2008-02-12T11:33:02Z")

</div>

myMethod does exist Harjo.

Again, I don’t want to continue with my twisted code and  
am looking for a very simple piece of code that can trigger a method that works for starters…

Regards,  
Ron

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 12, 2008, 11:39am UTC](https://forum.servoy.com/t/simple-popup-code/8723/11 "2008-02-12T11:39:26Z")

</div>

Here is some simple code:

```auto
// Lets define 2 menuitems that don't trigger any methods
var aMenu = new Array(
	plugins.popupmenu.createMenuItem('Item 1',null),
	plugins.popupmenu.createMenuItem('Item 2',null)
)

// Get the form element name that triggered this method
// Make sure the element does HAVE a name in the name property
var sElementName = elements[application.getMethodTriggerElementName()]
if (sElementName != null) {
	// we have a name, lets show the popup right under this element.
	plugins.popupmenu.showPopupMenu(sElementName, aMenu);
}

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.servoy.com/u/Ron)\
**Post date:** [February 12, 2008, 12:38pm UTC](https://forum.servoy.com/t/simple-popup-code/8723/12 "2008-02-12T12:38:38Z")

</div>

Yep, this code works!! , even calling a method works fine, thanks Robert.  
@Harjo & Patrick: thank you for your suggestions.

Regards,  
Ron
