I needed to do this recently, and after trying several different permutations (using onfocus, onclick of textbox, etc.), I finally settled on this ...
<input id="autocomplete" name="autocomplete" type="text" value="Choose Document"> <p> <button type="submit" value="Submit" name="submit" id="submit" > Submit </button> </p> <script type="text/javascript"> $("#autocomplete").autocomplete( { source: '@Url.Content("~/Document/DocumentTypeAutoComplete/")' </script>
This opens the ddl autocomplete list in focus (even if you have the default text in the input field as shown above).
It also automatically selects text in the text box so that the user cannot clear the text.
As soon as an element is selected from the autocomplete list, it places this element in the autocomplete input field and moves focus to another control (thus preventing the autocomplete from reopening).
I plan to replace it with adding dynamic Ajax calls to the very nice Chosen pick lists with Refreshing Melting Ice when I get a chance.
De Shan Baptiste Dec 10 '12 at 2:05 2012-12-10 02:05
source share