tedder42 tedder42 - 11 months ago 92
jQuery Question

input + datalist, default value, reset on select?

I'm using a

to allow selection of an option, yet still allow type-in values. Here's what I mean:

<input list="cities" name="city">
<datalist id="cities">
<option value="Portland">
<option value="San Francisco">

Once a city is chosen, opening the dropdown only shows that city unless I manually hit backspace to clear it. I thought I might fix that with jquery like this:

$('input[name=city]').click(function() {

That's great, but it doesn't work. I've seen in other examples how to remove a 'selected' flag (here also), but I don't see that it applies to a

Here's a jsfiddle: https://jsfiddle.net/tedder/ekaLc64t/2/

Answer Source

I am not sure if this is what you want, but try to change the code to:

  $('input[name=city]').focusin(function() {
  $('#xx').click(function() {