mah2602
mah2602

Reputation: 98

Auto results search form jquery

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

Answers (2)

Yury Tarabanko
Yury Tarabanko

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

Related Questions