At the time of using jQuery UI Autocomplete in PHP, many times you need to pass additional parameters to an autoComplete call. Here is a simple way to pass extra parameters to the source URL. In that case, you need to define a callback function to the source
option of autoComplete call. Also, you can pass multiple parameters using this approach. Your jQuery UI Autocomplete function would be like the following.
<script> $(function() { $( "#skills" ).autocomplete({ source: function(request, response) { $.getJSON( "search.php", { term:request.term, extraParams:$('#extra_param_field').val() }, response ); }, minLength: 2, select: function(event, ui){ //On select action } }); }); </script>
In the source file, you can get the term and additional parameters using the $_GET
variable.
$term = $_GET['term'];
$extraVar = $_GET['extraParams'];
You are the best
Thanks you so much Sir
Thanx for your script, but is there any way to make the search case insensitive ?
Very helpful clear code.
Thanks a lot..
Saved my day as well. Thank you 🙂
very nice
this was indeed helpful, thank you kindly!
Thanks for this!!
I have a problem, what about if I want to pass another value from the db in the same row selected?
For example If I’m looking for names into db and I also want to send the last name value of the name writed in the input?
Thanks a lot!!!
you saved my day.
many many thanks brother.
thanks, this is helpfull ^_^