I have a keyup event on an input. This event works fine for auto complete when you select a value and press enter. But it doesn't work when you click at an auto complete value.
Is there an event that i can use in such case?
I already tried the change one but it doesn't work.
Thanks!
Edit:
Maybe i was not clear but i am referring to the autocomplete feature that browsers have. I am not trying to build my own.
Example: I have the following event:
$('.product').keyup(searchByProduct);
When user clicks at this input the old values that he already typed shows up ( it's the browser that does this ). If he clicks on one of the values, the function searchByProduct is not called.
Which event do i have to register to track this click ( and that the input content has changed )?
This jQuery listenForChange extension does what you're after - it basically keeps a copy of the contents for each <input />
element, then periodically checks them all again for changes.
This catches the AutoFill'ed selections that the browser makes to the form, and raises the jQuery change
event for you - very nice :o)
Note: if you only have one input form element, simply comment out lines 28-31
Might be irrelvant if you are trying to implement the functionality yourself but jQuery-UI has a built in AutoComplete widget that works great and takes care of everything for you...
jQuery-UI autocomplete
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With