Link to home
Start Free TrialLog in
Avatar of chaitu chaitu
chaitu chaituFlag for India

asked on

jquery autocomplete

 $("#company").autocomplete({
			  source: function( request, response ) {
				    $.ajax({
				        url: "findByCompanyName",
				        data: {"company": request.term},
				        dataType: "json",
				        success: function( data ) {
				            response( $.map( data, function( item ) {
				                return {
				                    label: item.company,
				                    value: item.company,
				                    companyid: item.companyId
				                }
				            }));
				        }
				    });
				},
	          minLength: 1,
	          select: function(event, ui) {
	              $('#eventCompany').val(ui.item.company);
	              $('#companyName').val(ui.item.company);
	              $('#companyId').val(ui.item.companyId);
	          }
	      });

Open in new window


       above auto complete functionality working when i search the companies.when I select the company I need to call another AJAX call to get departments which are related to that company.Is it in onselect or onchange function?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chaitu chaitu

ASKER

at what time we can use onchange function and  on one more doubt is if no matches found in findByCompanyName ajax call then how do we handle that scenario?

change: function(event, ui) {
               
                }
why change event ? it's not a dropdown, it's an autocomplete list
select run each time you select a company in the autocomplete list
if no matches found in findByCompanyName ajax call then how do we handle that scenario?
what do you want to happen if no match found?

you can check how many company is returning here around line 7:
success: function( data ) {
                             if(data.length==0) { // no company found
// do something
                             }
                             else {
                                    response( $.map( data, function( item ) {