JQuery autocomplete text box

How to implement Autocomplete using jQuery when I click on a text field without typing anything. String [] will return a pre-built list.

+4
source share
3 answers
<pre>'<input type="text"/><div class=displayPanel></div>'</pre> 

$ jq ('input'). bind ('click', function () {

$ jq ('. displayPanel'). slideDown ('slow', function () {

this.text = textarray;

});

});

I do not know if this is what you need, but.

+2
source

The autocomplete plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ ) is your best choice, especially if you are in the AJAXy application, as it goes to your server and gets a list of features in real time .

Usage example:

 $("#sometextbox").autocomplete("search.php", { width: 260, selectFirst: false }); 

And then search.php may return:

 Great Bittern|Botaurus stellaris Little Bittern|Ixobrychus minutus American Bittern|Botaurus lentiginosus 

You can also dynamically generate output, because the plugin passes the text entered in querystring to the q parameter.

In response to running autocomplete without entering anything, the plugin does not support this, but it is quite simple to implement it in a hacker way:

The plugin intercepts an event of keyboard lock (or key press), for example (line 92 of non-minified code):

 $input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete",...) 

Therefore, you can make autostart work by doing something like:

 $("#autocompletedInput").click(function() { $(this).trigger(($.browser.opera ? "keypress" : "keydown") + ".autocomplete"); } 

Codes should trigger an event. You may need to pass a random key symbol to the trigger, so he wonders what is going on.

+2
source

Have you tried one of the jQuery autocomplete plugins?

i.e. http://plugins.jquery.com/project/js-autocomplete , but there are several others.

0
source

All Articles