Page 1 of 1

Finding which button was clicked on a list using a element.on("click",function() listener

Posted: Mon Mar 07, 2016 6:37 pm
by Joni de Campos

I have a page with alist or a grid that contains 2 buttons on each cell.

I am using a listener to find out when a user click on the cell, but what I need to have is to check which buttton on the cell was pressed...


Finding which button was clicked on a list using a element.on("click",function() listener

Posted: Mon Mar 07, 2016 6:52 pm
by Serhii Kulibaba

Hello Joni,

You can get the button, wich was clicked with JS below:
prevar button = event.target;/pre


Finding which button was clicked on a list using a element.on("click",function() listener

Posted: Mon Mar 07, 2016 7:33 pm
by Joni de Campos

I am getting a "ReferenceError: button is not defined"

Code:

element.on("click",function()

{
var button = event.target; // is not working

//here goes rest of code

}
);


Finding which button was clicked on a list using a element.on("click",function() listener

Posted: Mon Mar 07, 2016 9:05 pm
by Serhii Kulibaba

It is better to use Appery.io visual builder to add events' handlers instead of custom listeners: https://devcenter.appery.io/documenta...

If you need to use that option - please add parameter event to your function:
preelement.on("click",function(event) {
var button = event.target; // is not working
//here goes rest of code
});/pre


Finding which button was clicked on a list using a element.on("click",function() listener

Posted: Tue Mar 08, 2016 9:58 pm
by Joni de Campos

Thanks Sergiy, I missed the event on function (event).

It worked. Fantastic job !