7

I have some codes that should be run when a select element changes.I do it with jquery in this way:

$("#myselect").change(function() {
    .......
});

But I want these codes run also when user change the select using keyword arrows. As i found the event for this purpose is 'keyup' . So will be :

$("#myselect").keyup(function() {
   .......
});

How can i combine these two event?

hd.
  • 17,596
  • 46
  • 115
  • 165

2 Answers2

15

You can use .bind() to combine them:

$("#myselect").bind("change keyup", function(event){
   //Code here
});

See reference here.

AlexBay
  • 1,323
  • 2
  • 14
  • 26
0

You can write the function that you want to call separately, and then assign it to the events you want to handle, sth like:

var func = function(){};

$("#myselect").change(func()).keyup(func());
Jobin
  • 8,238
  • 1
  • 33
  • 52
Ibolit
  • 9,218
  • 7
  • 52
  • 96
  • As far as i know, you can't. You will have to iterate over the options of the select and ask each one of them if they are selected or not. Else you can use another jQuery filter, ":selected" to filter the selected option. – Ibolit Sep 06 '11 at 07:36
  • This is how you can find the selected option in your select: alert ($(this).children(":selected").attr("value")); – Ibolit Sep 06 '11 at 07:53