forked from nootanghimire/autocomplete-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
71 lines (59 loc) · 1.85 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<title>Test-Autocomplete</title>
<style>
/*This is responsible for every styling*/
#tag-div .tags{
padding-right: 10px;
padding-left:5px;
margin-left: 2px;
background-color: #aaa;
color: #fff;
font-size: smaller;
}
#list-div .list{
cursor: pointer;
transition:.3s;
border:1px solid #ddd;
}
#list-div .list:hover{
background-color: #a2e4b8;
color:white;
transition:.3s;
}
</style>
</head>
<body>
<form action="" id="myForm">
<span id="tag-div"></span><input type="text" id="complete">
<div id="list-div"></div>
</form>
</body>
<script src="autocomplete.js"></script>
<script>
//Write the config
var config = {
inputId:'complete', /* Which input field to hook on*/
path:"data.php", /* Where to get data*/
divList:"list-div", /* ID for div to list autocomplete status ( you need to create this div) */
divListEach:"list", /* class-name for each element in autocomplete (no need to create this div)*/
divTag:"tag-div", /* ID of element which will contain the selected thing */
elemClass:"tags", /* class of every element in tagged list */
getVar:"sent", /* The QueryString param*/
innerHTMLkey:"name" /* The object key that is to be used as innerHTML*/
}
//call the method
autocomplete.complete(config, function(data, output){
//alert(JSON.stringify(data));
//alert(JSON.stringify(output));
//tada! you have the selected data and the returned JSON data to play with.
//called on every selection made.
var leftBox = document.getElementById(config.inputId);
var myRect = leftBox.getBoundingClientRect();
var divObj = document.getElementById(config.divList)
var width = myRect.right - myRect.left;
divObj.setAttribute('style', "position:relative !important; left:"+ (myRect.left -5)+"px !important; width:"+width+"px; !important; border-radius:6px;");
});
</script>
</html>