tags:

views:

41

answers:

3

Hi everyone,

i am working with a select. I want to trigger and event when the user select a value.

I am using the event "change", the problem is that if a user open the select but choose the same option that is selected, the triggers doesn't fire.

Is there a way to capture the event when a user select an option independently if the option is the same than is the one that was selected?

thanks.

A: 

I'm not sure whether it's a cross-browser solution but something like this:

$("#mySelect option").click(function() {
    // do sth
});

Works well in Opera/Firefox.

Crozin
I have a lot of selects in the same page and i think this option would not be efficient. But thanks.
You can have many `select`s - I don't know why it could be a problem? Just use correct selector.
Crozin
A: 

I think the option you need is "click" instead of change.

lugte098
This will not work as expected because it will cause the event to fire as soon as you open the select to choose your option. Therefore if you plan to use the selection of a user in your code, it could be misleading.
ryanulit
+1  A: 

You can catch both the change and click events using the bind method. This should allow you to catch most keyboard and mouse interactions

$('selector').bind('click change',function() {})
Neil Aitken
If i put change the problem is that is fired when i click on the select to see the options.
How about keyup and mouseout? What is the final aim of this, As bears says above why do you need to re-fire an event if the value hasn't changed?
Neil Aitken