0

When i click on an <input type=text>, a list of old values appear. If I chose one of them with the mouse, the event "change" from jQuery doesn't trigger.

What event should/could I use to detect this?

John Conde
  • 217,595
  • 99
  • 455
  • 496
Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189
  • This is a common problem. You'd be better of disabling autocomplete on the form/field. See here: http://stackoverflow.com/a/11710295/551093 – Christian Apr 30 '13 at 13:09
  • @ChristianVarga no, you can use oninput. If not supported, see keyup, paste, change events – A. Wolff Apr 30 '13 at 13:11
  • @roasted I'm interested to know how `keyup` or `paste` would be fired when _"a value is chosen with the mouse"_. Also, the OP already stated `change` didn't work. – Christian Apr 30 '13 at 13:13
  • Same problems here: http://stackoverflow.com/questions/6050948/proper-handling-of-input-change-event/6052322#6052322 – Getz Apr 30 '13 at 13:13
  • @ChristianVarga oniput handle all these cases (paste,keyup,change...). I was just saying in case oniput is not supported, you can handle all this other events and maybe with CLICK too which should be fired when clicking on autocomplete dropdown. {this have to be verified if cross browser though} – A. Wolff Apr 30 '13 at 13:17
  • @roasted, nah, `click` isn't always fired when selecting an option from a browser-generated autocomplete dropdown. That's the problem, browser-generated autocompletes are really painful. Some of them don't generate _any_ event. – Christian Apr 30 '13 at 13:19
  • @ChristianVarga You are right, not possible using click. – A. Wolff Apr 30 '13 at 13:36

2 Answers2

2

You have to use oninput event, using jquery:

$('#myinput').on('input',function(){
    //your code here
});
A. Wolff
  • 74,033
  • 9
  • 94
  • 155
0

change will only trigger if field loose it's focus (blur event). And the term old values appear is browser feature that remembers form data for fields with same name. You can not trigger change event with that. You need an alternate event like paste , input.

$("#field").on("input DOMAttrModified paste",function(){
});

I'm not sure of event. You can try some though.

SachinGutte
  • 6,947
  • 5
  • 35
  • 58