In the following example I have an input field and accompanying datalist element. I am trying to write javascript that listens for when a user selects an item from the list. I have seen it suggested to use the "input" event for this, and in Chrome, Firefox, etc it all works. The problem is internet explorer.
In IE10 I get the following behavior:
- Typing in the field fires the event.
- Selecting an item from the datalist does not fire the event the first time.
- Reselecting the same option does fire the event.
See test:
$('input').on('input', function(){
console.log($('input').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input list="ice-cream-flavors" id="ice-cream-choice" name="ice-cream-choice" />
<datalist id="ice-cream-flavors">
<option value="Chocolate">
<option value="Coconut">
<option value="Mint">
<option value="Strawberry">
<option value="Vanilla">
</datalist>
Does anyone have any suggestions on how I can force internet explorer to fire that (or any) event so I can run a function when a user makes a selection?