Reputation: 3033
Welcome,
I have function
$('#myfield').keyup(function () { //do something }
//- do something is runing when user write something in myfield. I notice, when user use "auto complete" from browser, my function is not executed.
I found idea, to use focusout
Do you have any idea how can i combine that code together, without writing second function like this ?
$('#myfield').focusout(function () { //do something }
I would like to put this 2 functions together, and don't write //do something, two times.
regards
Upvotes: 7
Views: 10803
Reputation: 165
you can also write function seperately and give function name alone.. like...
$('#myfield').keyup(function_name).focusout (function_name);
function function_name() {
//do something
}
Upvotes: 0
Reputation: 8117
bind multiple events to input box
$('#myfield').bind("focusout",function(){
})
Upvotes: 1
Reputation: 630637
You can use .bind()
which takes a space separated list of events to bind your handler to, like this:
$('#myfield').bind("keyup focusout", function () {
//do something
});
Though, unless you need some special propagation, I'd stick with blur
over focusout
, just a preference really:
$('#myfield').bind("keyup blur", function () {
//do something
});
Upvotes: 19