Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check button is clicked inside a function

My Scenerio:

I have a function: The function Addprocedure() is called on onclick of Addprocedure button.
In this function i want to check if btnAddSelectedProcedures is clicked then do Something else do nothing

 function Addprocedure(){
        if()// Check if Button is clicked, button id = `btnAddSelectedProcedures`
           {
              //Do Something
           }
           else{
              //Do nothing
           }
    }
like image 576
Somnath Kharat Avatar asked Mar 09 '26 17:03

Somnath Kharat


1 Answers

Save the state of the button in a variable.

Define btnClicked globally as false. When btnAddSelectedProcedures is clicked, change btnClicked to true. When you call Addprocedure check if btnClicked variable is true and if so, that button has been clicked.

Example:

var btnClicked = false;

function Addprocedure() {
    if (btnClicked) {
        //Do something...
    } else {
        //Do something else...
    }
}

$('BUTTON[name="btnAddSelectedProcedures"]').click(function() {
    btnClicked = true;
});

$('BUTTON[name="Addprocedure"]').click(function() {
    Addprocedure();
});
like image 186
Jared Avatar answered Mar 12 '26 08:03

Jared



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!