开发者

Auto suggest feature to search records

I don't know what is the exact name of this feature, but I need a feature where the user should be given a text box to search things. When they type in this text box, a matching list of values from database should be shown like a drop-down box.

The user can select one of the va开发者_JS百科lue and for will got submit.

I know this is already done on Internet anywhere, but what is this feature called?

Where can I find this feature to download and use for free?


Autocomplete from jQuery UI . SAYT opensource from Google.

http://jqueryui.com/demos/autocomplete/

http://code.google.com/p/search-as-you-type/


I found this code somewhere online, very very useful and very fast (tested for 30000 strings), have been using it ever since,

it uses regex

var rx = new RegExp('"([^"]*' + search + '[^"]*)"', 'gi');
var i = 0;
var num;
results = '';
while (result = rx.exec(string)) {
    results += "\n" + result[1];
    i += 1;
    if (i >= 10) break;
}

I've put up the entire code on JSFiddle

NOTE: My code(The HTML part) is extremely messy, was trying too many things at once, just correct it to suit your requirements.


The easiest way to do this is to use the jQuery UI version here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜