Reputation: 98
I would like to have a search form (with more than one field) that would display the avaible results as the person types the value, geting these values from my database.
Doing some research I found the code below, but as you can see it works with words pre-defined by hand, and not using a database to recover values like I want.
Is there a way I can change this code, maybe the script, to achieve the result I want?
<head>
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
</body>
Upvotes: 0
Views: 1339
Reputation: 7663
you can see these two links
http://jqueryui.com/autocomplete/#remote-jsonp
http://jqueryui.com/autocomplete/#remote
if you are using php
http://www.simonbattersby.com/blog/jquery-ui-autocomplete-with-a-remote-database-and-php/
http://burnmind.com/howto/how-to-feed-jquery-uis-autocomplete-with-a-database-generated-dataset
if you are using asp.net
http://www.dotnetcurry.com/ShowArticle.aspx?ID=515
http://www.aspsnippets.com/Articles/Using-jQuery-AutoComplete-Plugin-in-ASP.Net.aspx
Upvotes: 2
Reputation: 45121
You need to use remote data source
$( "#tags" ).autocomplete({
source: "specify_url_to_your_server_here"
})
http://jqueryui.com/autocomplete/#remote
And of course you need some server-side to support this.
Upvotes: 0