Possible Duplicate:
jQuery autocomplete UI- I'd like it to start the search onfocus without the user having to type anything
jQuery UI Autocomplete
I want the options to appear as soon as my input is focused. Is there a setting for that? I tried setting minLength to 0, but it doesn't work... it still waits for a keypress.
$("#yourField").bind('focus', function(){ $(this).autocomplete("search"); } );
Here a jsfiddle: http://jsfiddle.net/fpHf4/2/ Updated one (for IE): http://jsfiddle.net/q9ERL/4/
As enlighted by @HoldOffHunger you must also set minLength to 0
I think u are breaking "autocomplete" utility just making a stylized select, thats the reason to wait for a keypress to have something to complete.
I know its not the anser u looking for, just remember this u trying to do just work with few options, if there are many u will get hard autocomple div load on firsts letters.
Or maybe u can have a 10 result records on ur sql query if is from this so get fast without loading all sort of results
--- I test focus bind on ie8, it fails, by the way its no a fail it does exactly what u want open div box on focus, the difference is that IE fires onFocus event whith jquery focus event, not like the others so su must evaluate on focus event if field its empty launch search , if is not just do nothing.. i hope this helps.
$("#yourField").bind('focus', function(){
if($(this).val()!=""){
$(this).autocomplete("search");
}
});
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