javascript - How to receive an event when selected option is the already selected option of a dropdown? -


motivation:

i want dynamically load select values ajax call, , allow user select first item in list once loaded , after gets focus, right now, first item selected item , when click dropdown , click first item nothing happens. can't add placeholder items not valid selections.

question:

how fire .change event in jquery when selected option reselected / not changed?

given following :

<select id="myoptions">   <option id="one" >option 1</option>   <option id="two">option 2</option> </select> 

assuming option one selected, , click on dropdown , select one again, event fires?

$('#myoptions').change(function() {     alert('you selected something!'); } 

the above code works if select different, if select selected option nothing happens.

in other words :

if click on dropdown , "select" selected option, how event fire?

not answers:

all these suggestions trigger not solutions, need fires when click on option 1 with mouse when option 1 selected option.

i tried using .click , nothing happens either.

none of answers working solution use case of very first time dropdown selected, , selects default selected option. nothing happens.

focusout not solution, doesn't happen until clicks somewhere else, late in game.

you can use click event or focusout. click event not work if user using keyboard tab + enter focusout work.

edit:

added demo: http://jsfiddle.net/fpre7/ click works click selected item.

$("#myoptions").on("click", function(){     console.debug("click"); });  $("#myoptions").on("change", function(){     console.debug("changed"); }); $("#myoptions").on("focusout", function(){     console.debug("focusout"); }); 

chrome 1 click (the choose one), ff 2 clicks, 1 click when open select , when choose one.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -