|
1 <!DOCTYPE html> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta charset="UTF-8" /> |
|
5 <title>jQuery UI Autocomplete Remote datasource demo</title> |
|
6 <link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" /> |
|
7 <script type="text/javascript" src="../../jquery-1.4.2.js"></script> |
|
8 <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script> |
|
9 <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script> |
|
10 <script type="text/javascript" src="../../ui/jquery.ui.position.js"></script> |
|
11 <script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script> |
|
12 <link type="text/css" href="../demos.css" rel="stylesheet" /> |
|
13 <script type="text/javascript"> |
|
14 $(function() { |
|
15 function log(message) { |
|
16 $("<div/>").text(message).prependTo("#log"); |
|
17 $("#log").attr("scrollTop", 0); |
|
18 } |
|
19 |
|
20 $("#birds").autocomplete({ |
|
21 source: "search.php", |
|
22 minLength: 2, |
|
23 select: function(event, ui) { |
|
24 log(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value); |
|
25 } |
|
26 }); |
|
27 }); |
|
28 </script> |
|
29 </head> |
|
30 <body> |
|
31 |
|
32 <div class="demo"> |
|
33 |
|
34 <div class="ui-widget"> |
|
35 <label for="birds">Birds: </label> |
|
36 <input id="birds" /> |
|
37 </div> |
|
38 |
|
39 <div class="ui-widget" style="margin-top:2em; font-family:Arial"> |
|
40 Result: |
|
41 <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> |
|
42 </div> |
|
43 |
|
44 </div><!-- End demo --> |
|
45 |
|
46 <div class="demo-description"> |
|
47 <p> |
|
48 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. |
|
49 </p> |
|
50 <p> |
|
51 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. |
|
52 </p> |
|
53 </div><!-- End demo-description --> |
|
54 |
|
55 </body> |
|
56 </html> |