1 | <!DOCTYPE html>
|
---|
2 | <html lang="en">
|
---|
3 | <head>
|
---|
4 | <meta charset="utf-8">
|
---|
5 | <title>jQuery UI Autocomplete - Remote datasource</title>
|
---|
6 | <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
|
---|
7 | <script src="../../jquery-1.6.2.js"></script>
|
---|
8 | <script src="../../ui/jquery.ui.core.js"></script>
|
---|
9 | <script src="../../ui/jquery.ui.widget.js"></script>
|
---|
10 | <script src="../../ui/jquery.ui.position.js"></script>
|
---|
11 | <script src="../../ui/jquery.ui.autocomplete.js"></script>
|
---|
12 | <link rel="stylesheet" href="../demos.css">
|
---|
13 | <style>
|
---|
14 | .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
|
---|
15 | </style>
|
---|
16 | <script>
|
---|
17 | $(function() {
|
---|
18 | function log( message ) {
|
---|
19 | $( "<div/>" ).text( message ).prependTo( "#log" );
|
---|
20 | $( "#log" ).scrollTop( 0 );
|
---|
21 | }
|
---|
22 |
|
---|
23 | $( "#birds" ).autocomplete({
|
---|
24 | source: "search.php",
|
---|
25 | minLength: 2,
|
---|
26 | select: function( event, ui ) {
|
---|
27 | log( ui.item ?
|
---|
28 | "Selected: " + ui.item.value + " aka " + ui.item.id :
|
---|
29 | "Nothing selected, input was " + this.value );
|
---|
30 | }
|
---|
31 | });
|
---|
32 | });
|
---|
33 | </script>
|
---|
34 | </head>
|
---|
35 | <body>
|
---|
36 |
|
---|
37 | <div class="demo">
|
---|
38 |
|
---|
39 | <div class="ui-widget">
|
---|
40 | <label for="birds">Birds: </label>
|
---|
41 | <input id="birds" />
|
---|
42 | </div>
|
---|
43 |
|
---|
44 | <div class="ui-widget" style="margin-top:2em; font-family:Arial">
|
---|
45 | Result:
|
---|
46 | <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
|
---|
47 | </div>
|
---|
48 |
|
---|
49 | </div><!-- End demo -->
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | <div class="demo-description">
|
---|
54 | <p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are bird names, displayed when at least two characters are entered into the field.</p>
|
---|
55 | <p>The datasource is a server-side script which returns JSON data, specified via a simple URL for the source-option. In addition, the minLength-option is set to 2 to avoid queries that would return too many results and the select-event is used to display some feedback.</p>
|
---|
56 | </div><!-- End demo-description -->
|
---|
57 |
|
---|
58 | </body>
|
---|
59 | </html>
|
---|