1

When I input some text in an <input type="text">, and the text matches some previously input text, the browser will present a dropdown and I can reuse that text.

enter image description here

But which javascript event will the input receive when that text is selected?

  • onkeydown/onkeyup does not trigger
  • onchange does not trigger.
  • In Firefox, it seems like onselect is triggered, but not in chrome. However, that event is used for other purposes.
  • onclick does not trigger.
  • onblur is as usually only triggered when the input loses focus.
Anders Lindén
  • 6,839
  • 11
  • 56
  • 109

1 Answers1

2

There is an interesting event named input:

JSFiddle example.

Html:

<form>
    <input id="text" name="text" type="text" />
    <input type="submit" value="Sumbit" />
</form>

Script:

$(document).ready(function()
{
    $('#text').on('input', function()
    {
        console.log('Changed to ' + this.value);
    });
});
Community
  • 1
  • 1
Regent
  • 5,142
  • 3
  • 21
  • 35