Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Autocomplete with multiple inputs

I have an autocomplete field which I would like to augment by providing a drop down for categories as well, in the hopes that this makes it even easier to search on. This would take the category id from the drop down and then pass this in along with the search text to my server side Autocomplete Function.

I am using the jQuery autocomplete plugin found here:

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

The demo page is here:

http://jquery.bassistance.de/autocomplete/demo/

Perhaps this is already explained in the demo somehow, but I'm just not seeing it. I am able to get the data out from JSON and split it into multiple fields.

It doesn't matter much, but I am using ASP.NET MVC as well.

like image 886
Anthony Potts Avatar asked Apr 08 '26 15:04

Anthony Potts


1 Answers

The first parameter of the autocomplete plugin can be an array or a url. All you would have to do is supply your category id as a query string parameter to your autocomplete function.

var selectedCategory = $('.categories').val();
var query = '';
if (selectedCategory !== 0)
{
   query = '?category=' + selectedCategory;
}
$("#suggest4").autocomplete('search_service.svc' + query, {
   // options   
});

Hope this helps.

like image 108
bendewey Avatar answered Apr 11 '26 05:04

bendewey