jquery Autosuggest
HTML
<input type='text' />
JavaScript
var json = [{"full_name": "joye dave", "username": "jd"}, {"full_name": "rob", "username": "r"}, {"full_name": "jhon key", "username": "jk"}, {"full_name": "alpacino", "username": "ap"}, {"full_name": "Julia", "username": "Julia"}];
function compare(a,b) {
if (a.full_name.toLowerCase() < b.full_name.toLowerCase())
return -1;
if (a.full_name.toLowerCase() > b.full_name.toLowerCase())
return 1;
return 0;
}
json.sort(compare);
$('input').autocomplete({
source: function (request, response) {
response( $.map( json , function(i){
return{
id: i.username,
value: i.full_name
}
}))
},
focus: function( event, ui ) {
$( "input" ).val( ui.item.id );
return false;
},
});