I have the following:
$('#<%=txtCity.ClientID%>').autocomplete({
source: function (request, response) {
var parameters = {
isoalpha2: '<%=Session["BusinessCountry"].ToString()%>',
prefixText: request.term
};
$.ajax({
url: '<%=ResolveUrl("~/AtomicService/Assets.asmx/GetCitiesWithState")%>',
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(parameters),
success: function (data) {
response($.each(data.d, function (index, value) {
return {
label: value.slice(value.indexOf(',')),
value: parseInt(value.split(',')[0])
}
}));
}
});
},
minLength: 2,
delay: 50,
select: function (event, ui) {
var city = ui.item.label.split(',')[0];
var state = ui.item.label.split(',')[1];
alert(city);
alert(state);
$('#<%=txtCity.ClientID%>').val(city);
$('#<%=txtState.ClientID%>').val(state);
},
});
It's all happy days, except when I select an item from the autocomplete list I'd like to not have autocomplete populate the $('#<%=txtCity.ClientID%>')
element. How do I do it? I saw .insertAfter
, is that something I should look at?
Help appreciated.