views:

274

answers:

2

I am trying to do this but keep on failing.

I have a text box. I have also an array of cities, and i want, while typing to display the cities that the user should be able to select.

Like if the user is typing : Mu the drop down should display Mumbai \n MuMu ... etc Like the Tags below is doing !

Does someone have any ideas in how this can be accomplished ?

+1  A: 

There are quite a lot different JQuery plugins for this purpose:

poke
That is good, but i am wondering if there is a non-jquery implementation perhaps.
Of course there is, but that would require quite a lot effort. Basic idea: When the text field changes, a script checks the content with the loaded database and displays a subset of the possible values so the user can select them.
poke
http://www.javascript-examples.com/autocomplete-demo/
poke
The effort isn't necessarily that much: the important thing to remember is to use `setInterval` to wait until there hasn't been a key-press for half a second, so that you don't set off a new query for every individual key-press. Aside from that it's no different from "do the query, refresh the list".
Daniel Earwicker
+1  A: 

Jquery autocomplete is one of the best for you

http://docs.jquery.com/Plugins/Autocomplete#source

http://docs.jquery.com/Plugins/Autocomplete#demo

Sachin