Repository navigation
Expand file tree
/
Copy pathsearch.html
More file actions
110 lines (103 loc) · 2.63 KB
/
Copy pathsearch.html
File metadata and controls
110 lines (103 loc) · 2.63 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html>
<head>
<title>Final Project</title>
<style>
#search_bar {
background-image: url('https://www.w3schools.com/css/searchicon.png');
background-position: 10px 12px;
background-repeat: no-repeat;
width: 95%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#bookTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#bookTable th, #bookTable td {
text-align: left;
padding: 12px;
}
#bookTable tr {
border-bottom: 1px solid #ddd;
}
#bookTable tr.header, #bookTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<input type="text" id="search_bar" onkeyup="myFunction()" placeholder="Search by book title/ genre/ author...">
<table id="bookTable">
<tr class="header">
<th style="width:28%;">Book Title</th>
<th style="width:20%;">Author</th>
<th style="width:20%;">Genre</th>
<th style="width:16%;">Number of Pages</th>
<th style="width:16%;">Aisle</th>
</tr>
<tr>
<td>Black Beauty</td>
<td>Anna Sewell</td>
<td>Children's Literature</td>
<td>255</td>
<td>C-25-45</td>
</tr>
<tr>
<td>Jane Eyre</td>
<td>Charlotte Bronte</td>
<td>Novel</td>
<td>592</td>
<td>N-03-24</td>
</tr>
<tr>
<td>Adventures of Huckleberry Finn</td>
<td>Mark Twain</td>
<td>Picaresque Fiction</td>
<td>366</td>
<td>F-15-02</td>
</tr>
<tr>
<td>House of Many Ways</td>
<td>Diana Wynne Jones</td>
<td>Young Adult Fiction</td>
<td>338</td>
<td>Y-17-14</td>
</tr>
<tr>
<td>'Salem's Lot</td>
<td>Stephen King</td>
<td>Horror Fiction</td>
<td>439</td>
<td>F-49-01</td>
</tr>
</table>
<script>
function myFunction() {
var input, filter, table, tr, td1, td2, td3, i;
input = document.getElementById("search_bar");
filter = input.value.toUpperCase();
table = document.getElementById("bookTable");
tr = table.getElementsByTagName("tr");
for (i=0; i<tr.length; i++) {
td1 = tr[i].getElementsByTagName("td")[0];
td2 = tr[i].getElementsByTagName("td")[1];
td3 = tr[i].getElementsByTagName("td")[2];
if (td1 || td2 || td3) {
if (td1.innerHTML.toUpperCase().indexOf(filter) > -1 || td2.innerHTML.toUpperCase().indexOf(filter) > -1 || td3.innerHTML.toUpperCase().indexOf(filter) > -1 ) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
</script>
</body>
</html>