Hi, I have a perfectly working code for auto populate textbox via rest api(it populates after 2 characters typed). Can you assist me on modifying the same api code to find out the total length of array(/total companies) and assign to textbox val something like $("#TotalCompany").val(...) I currently have autopopulate companies $("#Company").autocomplete working just fine.
$(document).ready(function () {
var baseServiceUrl = 'http://services.appserver.com/';
$("#Company").autocomplete({
minLength:
2,
source:
function (request, response) {
$.getJSON(baseServiceUrl + '/company/name/' + request.term + '/?callback=?',
{
contextKey: function () {
// applies to associated parties
var key =
$(this).parent().parent().find('.type').val();
if (key !== "--Select--" &&
key !== "")
key = key ===
"O" ? "Company" : "Company";
else
key =
"";
return key;
},
format: "json"
},
function (data) {
response($.map(data,
function (item) {
return {
label:
item['Company'].replace(/&/g, '&'),
value:
item['Company'].replace(/&/g, '&')
}
}));
}).sort();
}
});
});
The web service API return something simillar to the script
below:
<ArrayOfCompany xmlns="http://schemas.datacontract.org/2004/07/CR.WebServices.Model.EntityFramework" xmlns:i=http://www.w3.org/2001/XMLSchema-instance>
<Company>…</Company>
<Company>…</Company>
<Company>…</Company>
</ArrayOfCompany>
Please let me know if you need more details Greatly appreciated any help