chaitu chaitu
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);
}
});
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
select run each time you select a company in the autocomplete list
ASKER
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 ) {
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 ) {
ASKER
change: function(event, ui) {
}