Javascript – Explicitly calling the autocomplete function in jquery autocomplete plugin

autocompletejavascriptjquery

I have a text field to which I have a jquery autocomplete event attached. However, due to some reasons, I dont want the search results to appear when the user types, but rather when a button is pressed. I know this sounds lame, but I have my reasons. How do I trigger the autosearch results to appear by calling an explicit function?

Best Answer

Not sure what version of autocomplete you are using. If you use the latest version which is rolled into jQueryUI you can use the search method:

Search :: Signature: .autocomplete( "search" , [value] )

Triggers a search event, which, when data is available, then will display the suggestions; can be used by a selectbox-like button to open the suggestions when clicked. If no value argument is specified, the current input's value is used. Can be called with an empty string and minLength: 0 to display all items.