-
Notifications
You must be signed in to change notification settings - Fork 3
/
check.html
46 lines (40 loc) · 1.11 KB
/
check.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
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p class="emphy">Type any of USA, India, Argentina, Armenia</p>
<div class="container">
<input class="search-input" type="text" placeholder="Search here..." />
<div class="suggestions">
</div>
</div>
<script>
const countries = [
{name: 'USA'},
{name: 'India'},
{name: 'Argentina'},
{name: 'Armenia'}
];
const searchInput = document.querySelector('.search-input');
const suggestionsPanel = document.querySelector('.suggestions');
searchInput.addEventListener('keyup', function() {
const input = searchInput.value;
suggestionsPanel.innerHTML = '';
const suggestions = countries.filter(function(country) {
return country.name.toLowerCase().startsWith(input);
});
suggestions.forEach(function(suggested) {
const div = document.createElement('div');
div.innerHTML = suggested.name;
suggestionsPanel.appendChild(div);
});
if (input === '') {
suggestionsPanel.innerHTML = '';
}
});
</script>
</body>
</html>