move the select event outside the ajax function call
$('#<%=txtPinCode2.ClientID%>').autocomplete({
minChars: 1,
width: 6,
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "scm/BranchSearch.ashx?act=bnkb&BankCode=" + $('#<%=ddlBank.ClientID %> :selected').val() + "&PinCode=" + $('#<%=txtPinCode2.ClientID%>').val(),
data: "{}",
dataType: "json",
success: function (data) {
mydata = new Array();
for (var i = 0; i < data.length; i++) {
mydata.push({
label: data[i].BankBranchName,
value: data[i].BanckBranchCode
});
}
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response($.grep(mydata, function (arrItem) {
return matcher.test(arrItem.label);
}));
}
});
}
,
select: function (e, ui) {
alert(ui.item.label)
},
error: function (result) {
alert("No Match");
}
});