Using JQuery or JavaScript, I want to detect when a user selects a value, even if they don't change the already selected value.
How can this be accomplished?
I tried -
$('#MyID').select(function(){ /*my function*/ });
and
$('#MyID').change(function(){ /*my function*/ }); //nothing changing, so this fails
But they do not work.
Example - I have a dropdown with a list of years in it with nothing selected, the user selects "1976", I run a function. With "1976" selected, the user clicks on the dropdown again and selects "1976" again, I want to run the function again.
Try this code.
Try Here!
Have you tried .blur()?
Please note that you will have to click somewhere outside the dropdown menu on the page before the function will trigger. I don't know if this can be passed.
JsFiddle here
all systems go (on second click at least...)
Set a switch to run on selection, and reset the switch after it's captured and/or on
blur
.made a fiddle: http://jsfiddle.net/filever10/2XBVf/
edit: for keyboard support as well, something like this should work.
made a fiddle: http://jsfiddle.net/filever10/TyGPU/
Try this...
To get selected option's value...
and then get the text from the value
I've made a working jsfiddle only tested on firefox. I've managed to do what you want by adding a dummy option to the selectbox. This dummy option has a
display:none
style and won't be visible in the option list.DEMO