开发者

jQuery and PHP suggested answers

Hey guys, there is a fo开发者_开发问答rm where the user select some of his friends and I'm curious on how I can implement a list that searches simultaneously while the user is typing a friend's name and when he selects the name the name is written in the text box(jQuery). And if the user wants to select more than one friend, when I'm inserting the names in the database, how can I separate the names that are written in one input field?


You should take a look at the jquery auto-complete plugin:

http://docs.jquery.com/Plugins/autocomplete

Also, you could separate the names using commas.


Are you looking to write your own plugin or would you like to use an existing one?

If you want something ready made, here are a few examples

if you want something extremely light, only 6kb packed, this one would be the best choice
Autosuggest jQuery Plugin

Older one but still good

Tokenizing Autocomplete


This what already asked here on this site.

Facebook style JQuery autocomplete plugin

The accepted answer cited this jQuery code.

https://github.com/loopj/jQuery-Tokenizing-Autocomplete-Plugin


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

Although think twice about including the whole jquery ui library for this one plugin


I've implemented this a couple of times, it is not that difficult to achieve decent results and the basic idea that I used was...

1) create an input box.

2) create a div positioned directly underneath the input box.

3) create a jquery keypress handler. if there are more than x characters typed, ajax request.

4) loop through the results, and if they exist, append result divs to the result box.

5) show the result box.

I can dig up some example code if you would like. Not sure what you are talking about with the select multiple, but you could keep a variable of selected, and change the color of the result div when it is clicked on, this way many results can be selected and then processed later.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜