Binding Autocomplete Widget to Multiple Inputs
-
- $(function(){
- $(".courseTitle").each(function(){
- $(this).autocomplete({
source: function(request, response){
$.ajax({
url: 'courses.json',
dataType: 'json',
success: function(data){
var re = $.ui.autocomplete.escapeRegex(request.term);
var matcher = new RegExp("^" + re, "i");
response($.grep(data, function(item){
return matcher.test(item.label);
}));
}
});
},
minLength: 2,
select: function(event, ui){
$(this).val(ui.item.label); $(this).parent().next().children().val(ui.item.value);
return false;
},
focus: function(event, ui){
$(this).val(ui.item.label);
return false;
}
});
});
});
How can I attach this autocomplete widget to multiple inputs with the same class? Everytime I try, the first one works but no of the other ones do.