-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhello-typeahead.html
36 lines (31 loc) · 1.15 KB
/
hello-typeahead.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
<html>
<head>
<script>
var autocompleteWords = [
"Tomer", "To be or not to be", "Coc is the best",
"Coc is awesome",
"Hummus", "GT" ];
function complete(event) {
console.log("GOT ONE");
if(this.value && !event.ctrlKey) {
var text = this.value.toLowerCase();
for(var i = 0; i < autocompleteWords.length; i++) {
if(autocompleteWords[i].toLowerCase().indexOf(text) === 0) {
this.value = autocompleteWords[i];
this.setSelectionRange(text.length, autocompleteWords[i].length);
break;
}
}
}
}
window.onload = function() { // anonymous function
var inputBox = document.getElementById("typeahead");
inputBox.onkeyup = complete;
}
</script>
</head>
<body>
<h1>Autocomplete typeahead</h1>
<input type="text" id="typeahead" placeholder="Type Here"></input>
</body>
</html>