Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: event that tracks click in browser autocomplete

Tags:

jquery

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 )?

like image 603
Fernando Avatar asked Jan 13 '11 13:01

Fernando


2 Answers

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

like image 83
Andrew Avatar answered Nov 17 '22 23:11

Andrew


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

like image 1
stephen776 Avatar answered Nov 17 '22 23:11

stephen776