I am using these events to try to evaluate form input, but if the form is autofilled by the browser these events don't fire. How can I make the event fire on autofill as well?
-
I researched this a while ago and I don't believe you can, there is no event for a browser autofill. Would be interested in any answers though :) – Christian May 16 '12 at 01:43
-
Without knowing exactly what you're doing, could you add a `.change()` event handler as well? I'm honestly not even sure if that event even fires with browser autofill. – jaredhoyt May 16 '12 at 01:44
-
I'd try out `.change()` as Jared suggested, but if that doesn't work you might have to use `.blur()`. – nnnnnn May 16 '12 at 01:46
3 Answers
I know it's quite old question, but I solved the same problem using e.preventDefault() after the keyup function.
$("#email").keyup(function (e) {
e.preventDefault();
In this way if you select with enter the suggestion by the browser autofill it will notice. The problem still remains when you click with the mouse on the suggestion, but it works fine if you press any key after selected it.
FINAL SOLUTION
I found this post on stackoverflow: https://stackoverflow.com/a/24746108/3481005
and using .on("input") does the trick!
$("#email").on("input",function (e) {
There is no way to detect a browser autofill, unfortunately. Instead, use setInterval
, for example, to run a function at a fairly high frequency that checks whether the original value (or empty) matches the input value and trigger the response that way. If you don't want to do that, you're probably SOL since the browser will not even trigger .change
, and any event is most likely not cross-browser compliant.
You could also have the validation events run on form submission as well, which should be just as effective.

- 188,624
- 52
- 326
- 405
-
yea the problem with the on submission technique is I am changing the color of the input border based on the validation of the contents so I need the event to fire every time it's changed – A_funs May 16 '12 at 02:07
You can fake the desired behavior a bit by binding to the .click()
and/or .dblclick()
events.
It's not guaranteed, but you might snag an extra mouse click if they decide to "approve" the autocomplete by selecting it from the box.

- 3,104
- 2
- 29
- 37