-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchbar.js
66 lines (58 loc) · 2.54 KB
/
searchbar.js
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
let availableKeywords = [
{ keyword: "Html", link: "webdevelopment.html" },
{ keyword: "web development", link: "webdevelopment.html" },
{ keyword: "fullstack web development", link: "webdevelopment.html" },
{ keyword: "backend development", link: "webdevelopment.html" },
{ keyword: "frontened development", link: "webdevelopment.html" },
{ keyword: "JavaScript", link: "javascript.html" },
{ keyword: "c programming", link: "c.html" },
{ keyword: "c language", link: "c.html" },
{ keyword: "c++ programming", link: "c.html" },
{ keyword: "c++ language", link: "c.html" },
{ keyword: "dsa", link: "dsa.html" },
{ keyword: "data structures and algorithms", link: "dsa.html" },
{ keyword: "ai", link: "ai.html" },
{ keyword: "artificial intelligence", link: "ai.html" },
{ keyword: "machine learning", link:"machineLearning.html" },
{ keyword: "ml", link:"machineLearning.html" },
{ keyword: "neural networks", link:"neuralNetworks.html" },
{ keyword: "deep learning", link:"neuralNetworks.html" },
{ keyword: "data science", link:"dataScience.html" },
{ keyword: "data analytics", link:"dataScience.html" },
{ keyword: "data visualisation", link:"dataScience.html" },
{ keyword: "python programming", link:"python.html" },
{ keyword: "operating system", link:"os.html" },
{ keyword: "os", link:"os.html" },
{ keyword: "linux", link:"os.html" },
{ keyword: "coa", link:"coa.html" },
{ keyword: "computer organization and architecture", link:"coa.html" },
];
const resultBox = document.querySelector(".result-box");
const inputBox = document.getElementById("input-box");
inputBox.onkeyup = function () {
let result = [];
let input = inputBox.value;
if (input.length) {
result = availableKeywords.filter((item) => {
return item.keyword.toLowerCase().includes(input.toLowerCase());
});
console.log(result);
}
display(result);
if (!result.length) {
resultBox.innerHTML = '';
}
};
function display(result) {
const content = result.map((item) => {
return `<li onclick="selectInput(this)">${item.keyword}</a></li>`;
});
resultBox.innerHTML = "<ul>" + content.join('') + "</ul>";
}
function selectInput(list) {
const selectedKeyword = list.textContent;
const selectedItem = availableKeywords.find((item) => item.keyword === selectedKeyword);
if (selectedItem) {
window.location.href = selectedItem.link;
}
}