-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
60 lines (58 loc) · 2.47 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://www.w3.org/2005/10/profile">
<title>jQuery AutoCompleter example</title>
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"
type="text/javascript"></script>
<script src="jquery.autocompleter.js" type="text/javascript"></script>
<link href="jquery.autocompleter.css" rel="Stylesheet" media="all" type="text/css" charset="utf-8"/>
<script type="text/javascript">
$(function() {
$("#autocompleter").autoCompleter({
rowHash: true,
queryCallback: function(successCallback) {
// grabs the content of the textarea and feeds it to the autocompleter
var text = $("#input_data").val();
var results = [];
var splitText = text.split("\n");
$.each(splitText, function() {
var row = this.split(":");
var value = row[0].replace(/^ +/, "").replace(/ +$/, "");
var display = row[1].replace(/^ +/, "").replace(/ +$/, "");
results.push({ value: value, display: display});
});
successCallback({ results: results });
},
confirmSuggestionCallback: function(value, html) {
$("#value").attr("value", value);
},
selectRowCallback: function(value, display) {
// If you uncomment the following, 'display' gets written to the
// input box instead of 'value'
//this.$input.val(display);
}
}).one("focus", function() {
// remove the default text
$(this).attr("value", "")
});
});
</script>
</head>
<body>
<h1>jQuery AutoCompleter example</h1>
<p>
<h2>Input data</h2>
<textarea id="input_data" cols="60">jquery: <strong>jquery</strong>
autocompleter: <em>autocompleter</em></textarea>
<div>The <key>: <value> pairs in this example will be used to
fill the autocomplete box</div>
<div>The <em>key</em> is what will be written in the input box</div>
<div>The <em>value</em> is displayed in the autocompleter dropdown</div>
<div>Feel free to modify existing values or add new values</div>
</p>
<p>
<h2>Autocompleter</h2>
<input id="autocompleter" type="text" value="Please key in something"/>
<input id="value" type="text"/>
</p>
</body>
</html>