Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

JavaScript
$(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 similar to the script below:





Please let me know if you need more details Greatly appreciated any help

What I have tried:

<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>
Posted
Updated 20-Aug-20 18:28pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900