jQuery Autocomplete plugin using extraParams

jQuery Autocomplete plugin makes an input or textarea autocompleteable.

autocomplete( url or data, [options] )

Let's make an example to using extraParams to pass additional get variables:

HTML:

Javascript:
$('#txtAuto').autocomplete('search.php', {
extraParams: {
filter: function(){
return $('#txtFilter').val();
}
}
})

The above code following jQuery Autocomplete Plugin, is NOT working for me. So I do other way.

Javascript:
$('#txtAuto').autocomplete('search.php', {
mustMatch: false
}
})
$('#txtAuto').setOptions({
extraParams:{filter: function(){return $('#txtFilter').val();}
}
});

It's working now!

Note: mustMatch option should be set to false to prevent autocomplete calling search.php again after you select item.

Correct me if i'm wrong :)

Happy coding!

Comments

mike said…
Exactly what I needed. Thanks.
prakash said…
I was in search of a similar solution, i tried it out, but i got
$("#acnew").setOptions is not a function error, any suggestion would be appreciated.
Anonymous said…
Ok, I wasted 4 hours for searching this. Thank you so much!!
nvk said…
how i can receive this data in php