I have 3 textboxes, and on the keyup
event for all 3, I want to call the same function?
In the below code, I am tring to bind keyup
event to CalculateTotalOnKeyUpEvent
function to a textbox named compensation
, but it doesn't work:
$("#compensation").bind("keyup", CalculateTotalOnKeyUpEvent(keyupEvent));
function CalculateTotalOnKeyUpEvent(keyupEvent) {
var keyCode = keyupEvent.keyCode;
if (KeyStrokeAllowdToCalculateRefund(keyCode)) {
CalculateTotalRefund();
}
};
You need do like this:
// Edit according to request in the comment:
// in order to select more than one element,
// you need to specify comma separated ids.
// Also, maybe you need to consider to use a CSS class for the selected elements,
// then it could be just $(".className")
$("#element1, #element2, ....").bind("keyup", CalculateTotalOnKeyUpEvent);
You need to pass the function as a parameter, you do not need to pass the function as it was declared.
$("#txt1, #txt2, #txt3").keyup(fn);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With