JQuery's AutoComplete plugin result

Source: Internet
Author: User

jquery's autocomplete plugin was used in the work, but the problem of non-routine use was encountered.

One is the drop-down menu display and fill in the result of the text box requires a different string, that is, display the user name, the department, but filled in the text box is the user name and phone number

The second is after the user select, need to trigger the event, the user's ID to another hidden text box

First of all, I was lazy, so Google on the internet a bit of technical solutions, found to be more complex. After studying AutoComplete's online doc for the purpose of laziness, we found that there was a very simple solution.

The first is to apply the Formatitem and FormatResult functions of AutoComplete

Returns the data set, lazy people have lazy way, the string is separated by commas to represent, one line result:

"Name1,department1,tel1,id1/r/n NAME2, Department2,tel2,id2"

Formatitem: Drop-down menu data display customization, this shows only user name and department

Formatitem:function (data, I, N) {

var array = data.tostring (). Split (', ');
return array[0] + '/' + array[1];

}
FormatResult: Fill in the result of the text box, here fill in the user name and telephone number formatitem:function (data, I, N) {

var array = data.tostring (). Split (', ');
return array[0] + ', ' + array[2];

}

Finally, the callback function, to save the user ID in a hidden text box, this autocomplete provides a sub-function. Result (), which is used to callback other functions after selecting the result
Continue to use the universal Split function to split the result string

$ (' Inputfield '). AutoComplete (URL, {options}). result
(Function (event, data, formatted) {
var array = data.tostring (). Split (', ');
$ ("HiddenField"). Val (Array[3]);

});
The Lazy AutoComplete application is completed.


This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/batman9956/archive/2010/08/17/5816997.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.