How to identify the button pressed

Questions, tips and tricks and techniques for scripting in Servoy

How to identify the button pressed

Postby Ron » Sat Jul 25, 2009 2:29 pm

Hi all,

In FM I could point several buttons to the same method using a scriptparameter.
With some if statements I could distinguish which button was pressed and run
parts of the method.
This must be very simple but I can't see how.

if (forms.main.elements['name'] == 'buttonname1' )
{
//do stuff
}
if (forms.main.elements['name'] == 'buttonname2' )
{
//do stuff
}
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Re: How to identify the button pressed

Postby ROCLASI » Sat Jul 25, 2009 2:46 pm

Hi Ron,

You just give the buttons a unique name and use the following piece of code to fetch the clicked buttonname:
Code: Select all
var _sBtn = application.getMethodTriggerElementName();


Then you simply can use a switch statement to do your stuff:
Code: Select all
switch(_sBtn)
{
case "buttonname1":
   //do stuff
   break;
case "buttonname2":
   //do stuff
   break;
case "buttonname3":
   //do stuff
   break;
}

Just make sure the name property of the button(s) is filled.


Hope this helps
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: How to identify the button pressed

Postby Ron » Sat Jul 25, 2009 3:46 pm

Thanks very much Robert.

Regard,
Ron
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 36 guests

cron