1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
5 <title>jQuery Autocomplete Plugin</title>
6 <script type="text/javascript" src="../lib/jquery.js"></script>
7 <script type='text/javascript' src='../lib/jquery.bgiframe.min.js'></script>
8 <script type='text/javascript' src='../lib/jquery.ajaxQueue.js'></script>
9 <script type='text/javascript' src='../lib/thickbox-compressed.js'></script>
10 <script type='text/javascript' src='../jquery.autocomplete.js'></script>
\r
11 <script type='text/javascript' src='localdata.js'></script>
12 <link rel="stylesheet" type="text/css" href="main.css" />
13 <link rel="stylesheet" type="text/css" href="../jquery.autocomplete.css" />
14 <link rel="stylesheet" type="text/css" href="../lib/thickbox.css" />
16 <script type="text/javascript">
17 $().ready(function() {
19 function findValueCallback(event, data, formatted) {
\r
20 $("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
23 function formatItem(row) {
24 return row[0] + " (<strong>id: " + row[1] + "</strong>)";
26 function formatResult(row) {
27 return row[0].replace(/(<.+?>)/gi, '');
30 $("#suggest1").autocomplete(cities);
31 $("#month").autocomplete(months, {
38 formatItem: function(data, i, total) {
39 // don't show the current month in the list of values (for whatever reason)
40 if ( data[0] == months[new Date().getMonth()] )
45 $("#suggest13").autocomplete(emails, {
50 formatItem: function(row, i, max) {
51 return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
53 formatMatch: function(row, i, max) {
54 return row.name + " " + row.to;
56 formatResult: function(row) {
60 $("#singleBirdRemote").autocomplete("search.php", {
\r
64 $("#suggest14").autocomplete(cities, {
68 $("#suggest3").autocomplete(cities, {
73 $("#suggest4").autocomplete('search.php', {
77 formatItem: formatItem,
78 formatResult: formatResult
\r
80 $("#imageSearch").autocomplete("images.php", {
86 formatItem: function(data, i, n, value) {
87 return "<img src='images/" + value + "'/> " + value.split(".")[0];
89 formatResult: function(data, value) {
90 return value.split(".")[0];
93 $("#tags").autocomplete(["c++", "java", "php", "coldfusion", "javascript", "asp"], {
98 multipleSeparator: " ",
104 $(":text, textarea").result(findValueCallback).next().click(function() {
\r
105 $(this).prev().search();
\r
107 $("#singleBirdRemote").result(function(event, data, formatted) {
109 $(this).parent().next().find("input").val(data[1]);
111 $("#suggest4").result(function(event, data, formatted) {
112 var hidden = $(this).parent().next().find(">:input");
113 hidden.val( (hidden.val() ? hidden.val() + ";" : hidden.val()) + data[1]);
115 $("#suggest15").autocomplete(cities, { scroll: true } );
116 $("#scrollChange").click(changeScrollHeight);
118 $("#thickboxEmail").autocomplete(emails, {
122 highlightItem: false,
123 formatItem: function(row, i, max, term) {
124 return row.name.replace(new RegExp("(" + term + ")", "gi"), "<strong>$1</strong>") + "<br><span style='font-size: 80%;'>Email: <" + row.to + "></span>";
126 formatResult: function(row) {
131 $("#clear").click(function() {
132 $(":input").unautocomplete();
136 function changeOptions(){
137 var max = parseInt(window.prompt('Please type number of items to display:', jQuery.Autocompleter.defaults.max));
139 $("#suggest1").setOptions({
145 function changeScrollHeight() {
146 var h = parseInt(window.prompt('Please type new scroll height (number in pixels):', jQuery.Autocompleter.defaults.scrollHeight));
148 $("#suggest1").setOptions({
154 function changeToMonths(){
156 // clear existing data
158 // change the local data to months
159 .setOptions({data: months})
162 // update the label tag
163 .text("Month (local):");
171 <h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/">jQuery Autocomplete Plugin</a> Demo</h1>
175 <form autocomplete="off">
177 <label>Single City (local):</label>
178 <input type="text" id="suggest1" />
179 <input type="button" value="Get Value" />
180 <input type="button" value="Change Max Items" onclick="changeOptions();" />
181 <input type="button" value="Change to Month Data" onclick="changeToMonths();" />
182 <input type="button" value="Change scroll height" id="scrollChange" />
185 <label>Month (local):</label>
186 <input type="text" id="month" />
187 <input type="button" value="Get Value" />
188 (Current month is excluded from list)
191 <label>E-Mail (local):</label>
192 <input type="text" id="suggest13" />
193 <input type="button" value="Get Value" />
196 <label>Single Bird (remote):</label>
197 <input type="text" id="singleBirdRemote" />
198 <input type="button" value="Get Value" />
201 <label>Hidden input</label>
205 <label>Single City (contains):</label>
206 <input type="text" id="suggest14" />
207 <input type="button" value="Get Value" />
210 <label>Multiple Cities (local):</label>
\r
211 <textarea id='suggest3' cols='40' rows='3'></textarea>
\r
212 <input type="button" value="Get Value" />
\r
215 <label>Multiple Birds (remote):</label>
216 <textarea id='suggest4'></textarea>
\r
217 <input type="button" value="Get Value" />
220 <label>Hidden input</label>
221 <textarea></textarea>
224 <label>Image search (remote):</label>
225 <input type="text" id='imageSearch' />
226 <input type="button" value="Get Value" />
229 <label>Tags (local):</label>
230 <input type="text" id='tags' />
231 <input type="button" value="Get Value" />
234 <label>Some dropdown (<3 IE):</label>
236 <option value="">Item 12334455</option>
237 <option value="2">Item 2</option>
238 <option value="3">Item 3</option>
239 <option value="4">Item 4</option>
243 <input type="submit" value="Submit" />
247 <a href="#TB_inline?height=155&width=400&inlineId=modalWindow" class="thickbox">Click here for an autocomplete inside a thickbox window.</a> (this should work even if it is beyond the fold)
250 <div id="modalWindow" style="display: none;">
252 <label>E-Mail (local):</label>
253 <input type="text" id="thickboxEmail" />
254 <input type="button" value="Get Value" />
258 <button id="clear">Remove all autocompletes</button>
260 <a href="search.phps">PHP script used to for remote autocomplete</a>
262 <h3>Result:</h3> <ol id="result"></ol>
265 <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
267 <script type="text/javascript">
268 _uacct = "UA-2623402-1";