Tuesday, September 7

 

jQuery Autocomplete plugin using extraParams

Digg! delicious Google Bookmark Reddit Slashdot Yahoo my Web stumbleupon Technorati

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!

3 Comments:

Anonymous mike said...

Exactly what I needed. Thanks.

December 12, 2010 12:49 PM  
Blogger 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.

June 13, 2011 5:26 PM  
Anonymous Anonymous said...

Ok, I wasted 4 hours for searching this. Thank you so much!!

February 9, 2012 4:43 PM  

Post a Comment

Links to this post:

Create a Link

<< Home