Reputation: 569
I want to use autocomplete with .live function, but it gives syntax error
$("input[name=point]").live(function() {
$(this).autocomplete({
minLength:0, //for local data
delay:0, //for local data
source:function(request,response){
//var param= {"action":"getSalePoints"};
$.getJSON("controllers/Order.controller.php?action=getSalePoints",request,function(result){
//create array for response objects
var suggestions = [];
//process response
$.each(result, function(i, val){
//alert(val.number);
suggestions.push(val.number);
});
//pass array to callback
response(suggestions);
});
},
select: function( event, ui ) {
var param={
"action":"getSalePointNo",
"point":ui.item.value
};
$.getJSON("controllers/Order.controller.php",param,function(result){
if(result == "0"){
$('#resultMsg').attr('class','errorMsg');
}
else{
alert(result);
$('[name=pointNo]', $(this).parents(".bill")).val(no);
}
});
}
});
});
Upvotes: 0
Views: 4221
Reputation: 1822
As 'mu is to short' suggested, you are not supplying the event type to the live function, you can try using 'focus' as the event type, try:
$("input[name=point]").live("focus", function() {
$(this).autocomplete({
minLength:0, //for local data
delay:0, //for local data
source:function(request,response){
//var param= {"action":"getSalePoints"};
$.getJSON("controllers/Order.controller.php?action=getSalePoints",request,function(result){
//create array for response objects
var suggestions = [];
//process response
$.each(result, function(i, val){
//alert(val.number);
suggestions.push(val.number);
});
//pass array to callback
response(suggestions);
});
},
select: function( event, ui ) {
var param={
"action":"getSalePointNo",
"point":ui.item.value
};
$.getJSON("controllers/Order.controller.php",param,function(result){
if(result == "0"){
$('#resultMsg').attr('class','errorMsg');
}
else{
alert(result);
$('[name=pointNo]', $(this).parents(".bill")).val(no);
}
});
}
});
});
Upvotes: 6
Reputation: 434615
The live
function takes two arguments:
.live( eventType, handler )
Description: Attach a handler to the event for all elements which match the current selector, now and in the future.
You're not supplying the eventType
so you'll be triggering an error inside jQuery as it tries to work with a function as a string and an undefined
value as a function.
Upvotes: 1