Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  133] [ 6]  / answers: 1 / hits: 17347  / 15 Years ago, thu, july 16, 2009, 12:00:00

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();
}
};

More From » jquery

 Answers
35

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.


[#99115] Sunday, July 12, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dahlias

Total Points: 730
Total Questions: 104
Total Answers: 101

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;