This topic is locked
[SOLVED]

Get Button Label

10/7/2021 5:35:05 PM
PHPRunner General questions
A
AlphaBase author

I want to add custom buttons based upon the same script to a grid. I need to get the LABEL of the button so that the script which will use a Switch statement (based upon the button label) will execute correctly.

How do I get the button label?

Myr0n 10/9/2021

You can use the next code in JavasScript Onload event

if($("span[data-itemid=Button_With_Unknown_Label]").find("a").text() =='Credit'){
//Do something
}else{
//Do something else
}

Keep in mind to change 'Button_With_Unknown_Label' for your button name

A
AlphaBase author 10/9/2021

Thanks MAlexArc. But I don't think that will work. Remember, I want to run the same script from a bunch of different buttons. Depending upon the button label, the script executes accordingly. AFAIK, each button has to have a unique name so...

Myr0n 10/15/2021

if that is the case add the next code in custom_function.js

/*
*Parameter: buttonName
*Usage: getLabelFromButton('data-itemid-name');
*/
function getLabelFromButton(buttonName){
var buttonToGetLabel = "span[data-itemid="+buttonName+"]";
return $(buttonToGetLabel).find("a").text();
}

You can call that function from wherever you want

A
AlphaBase author 10/15/2021

Okay, thanks much Myr0n. That should work.

T
Tuong Do 10/29/2021

Hi MyrOn

If the same button is on the the same view page more than once

eg two instance of that button is on the same view page and the button name can not be the same.

Is there a way to tell which instance of the button is clicked in the Client Before event