Jquery AutoComplete multi-field

Source: Internet
Author: User

The text box automatically matches the phone number and name, and the data is the JSON data that is found, which encapsulates all objects (telephone, cellphone, name). Select a phone number,

The code for automatically filling a name is as follows:

$. Ajax ({

URL: '/account/ajaxfinduserphonelist ',

Type
: 'Post ',

Cache: false,

Contenttype: "application/JSON ",

Datatype: "JSON ",

Success: function (data ){
$ ("# Input_pair_phone"). AutoComplete (data ,{
MAX: 50, // number of entries in the list

Minchars: 0, // minimum character entered before the activation is completed automatically

Width: 210,

Scrollheight: 1000, // The height of the prompt. the scroll bar is displayed if it overflows.

Matchcontains: True, // contains matching, that is, the data in the data parameter, whether the data in the package text box is displayed

AutoFill: false, // Auto Fill

Formatitem: function (row, I, max ){


If (row. Telephone! = NULL & Row. Telephone! = 'Null' & Row. Telephone! = ''){


Return row. Telephone + ''+ row. Name;


} Else if (row. cellphone! = NULL & Row. Telephone! = 'Null' & Row. cellphone! = ''){


Return row. Cellphone + ''+ row. Name;


}

},

Formatmatch: function (row, I, max ){


If (row. Telephone! = NULL & Row. Telephone! = 'Null' & Row. Telephone! = ''){


Return row. Telephone + ''+ row. Name;

} Else if (row. cellphone! = NULL & Row. Telephone! = 'Null' & Row. cellphone! = ''){


Return row. Cellphone + ''+ row. Name;


}

},

Formatresult: function (ROW ){


If (row. Telephone! = NULL ){


Return row. Telephone;


} Else if (row. cellphone! = NULL ){


Return row. Cellphone;


}


}


}). Result (function (event, row, formatted ){


If (row. Telephone! = NULL | row. cellphone! = NULL ){


$ ('# Input_pair_phone_name'). Val (row. Name );


}
});
}

});

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.