-
Notifications
You must be signed in to change notification settings - Fork 8
/
search.html
321 lines (232 loc) · 13.5 KB
/
search.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Store</title>
<script src="./include/prodbs.js"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="src/SimpleStarRating.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" />
</head>
<body>
<div class="container">
<div class="header"><a href="#"><img src="./logo2.jpg" alt="not found" name="Insert_logo" width="20%" height="90" id="Insert_logo" style="background-color: #8090AB; display:block;" /></a>
</div>
<div class="button">
<button id="btn001" type="button">Sign Up!</button>
<button id="btn002" type="button" class="fas fa-shopping-cart fa-2x"></button>
</div>
<!-----search bar----->
<form class="srcbartn" action="search.html" >
<input type="text" id="srch001" placeholder="Product Search.." name="search" onclick="listFunction()" onkeyup="searchFunction()" autocomplete = "off">
<button type="submit" ><i class="fa fa-search"></i></button>
<ul id="productline"></ul>
</form>
<script>
function listFunction(){
var prdlin = document.getElementById("productline");
var allist = "" ;
for (i = 0 ; i < prodb.length ; i++)
{
allist += "<li id= 'liid" + i + "'><a href='product.html'>" + prodb[i].pname + "</a><li>" ;
}
prdlin.innerHTML += allist;
var onclikoff = document.getElementById("srch001");
onclikoff.removeAttribute("onclick");
}
function searchFunction(){
var input, filter, i, txtValue ;
input = document.getElementById("srch001");
filter = input.value.toUpperCase();
for (i = 0; i < prodb.length; i++) {
var idname = "liid" + i ;
var iddom = document.getElementById (idname);
txtValue = prodb[i].pname;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
iddom.style.display = "";
} else {
iddom.style.display = "none";
}
}
}
</script>
<!----- End search bar----->
<div class="content">
<h1>Your Shop</h1>
<h2>Search</h2>
<!-----Start Featured nav------->
<nav class="product-filter">
<h1>Toys</h1>
<div class="sort">
<div class="collection-sort">
<label>Filter by:</label>
<select id="sel1" onchange = "filterFunc()">
<option value="all toys">all toys</option>
<option value="gun">Gun</option>
<option value="doll">Doll</option>
<option value="other">Other</option>
</select>
</div>
<div>
<label>Sort by:</label>
<select id="sel2" onchange = "sortFunc()">
<option value="nosort">No sort</option>
<option value="price">Price</option>
<option value="featured">Featured</option>
</select>
</div>
</div>
</nav>
<!------End Featured nav------>
<!-----Start Featured Product------->
<section class="products" id="sectionpart">
<div class="product-card" id = "doll1">
<div class="product-image">
<img src="./img/toy1.jpg" class="primg0" alt="unavailable">
</div>
<div class="product-info">
<h5>Plashy Toy</h5>
<h6>$19.99</h6>
<!-----start rating----->
<span class="rating" data-default-rating="4.5"></span>
<!-----end rating----->
</div>
</div>
<div class="product-card" id = "doll2">
<div class="product-image">
<img src="./img/toy2.jpg" class="primg0" alt="unavailable">
</div>
<div class="product-info">
<h5>Teddy Bear</h5>
<h6>$9.99</h6>
<!-----start rating----->
<span class="rating" data-default-rating="3.5"></span>
<!-----end rating----->
</div>
</div>
<div class="product-card" id = "gun1">
<div class="product-image">
<img src="./img/gun1.jpg" class="primg0" alt="unavailable">
</div>
<div class="product-info">
<h5>Toy Gun</h5>
<h6>$12.08</h6>
<!-----start rating----->
<span class="rating" data-default-rating="4"></span>
<!-----end rating----->
</div>
</div>
<div class="product-card" id = "other">
<div class="product-image">
<img src="./img/toy3.jpg" class="primg0" alt="unavailable">
</div>
<div class="product-info">
<h5>Circles</h5>
<h6>$20.19</h6>
<!-----start rating----->
<span class="rating" data-default-rating="2"></span>
<!-----end rating----->
</div>
</div>
</section>
<!-----End Featured Product------->
<div id="product-list"></div>
</div>
<div class="footer">
<script src="./src/SimpleStarRating.js"></script>
<script>
var ratings = document.getElementsByClassName('rating');
for (var i = 0; i < ratings.length; i++) {
var r = new SimpleStarRating(ratings[i]);
ratings[i].addEventListener('rate', function(e) {
console.log('Rating: ' + e.detail);
});
}
</script>
<script>
function filterFunc() {
var prodfilter = document.getElementById ("sel1");
var dollvar1 = document.getElementById("doll1");
var dollvar2 = document.getElementById("doll2");
var gunvar = document.getElementById("gun1");
var othervar = document.getElementById("other");
var comparevalue = prodfilter.value;
if (comparevalue == "gun"){
dollvar1.style.display = "none";
dollvar2.style.display = "none";
othervar.style.display = "none";
gunvar.style.display = "block";
}
else if (comparevalue == "doll"){
othervar.style.display = "none";
gunvar.style.display = "none";
dollvar1.style.display = "block";
dollvar2.style.display = "block";
return;
}
else if (comparevalue == "other"){
dollvar1.style.display = "none";
dollvar2.style.display = "none";
gunvar.style.display = "none";
othervar.style.display = "block";
}
else {
othervar.style.display = "block";
gunvar.style.display = "block";
dollvar1.style.display = "block";
dollvar2.style.display = "block";
}
}
</script>
<script>
function sortFunc(){
var prodsort = document.getElementById ("sel2");
var dollvar01 = document.getElementById("doll1");
var dollvar02 = document.getElementById("doll2");
var gunvar0 = document.getElementById("gun1");
var othervar0 = document.getElementById("other");
var comparevalue = prodsort.value;
var newnodesort = document.getElementById("sectionpart");
var childmaker = " ";
if (comparevalue == "price"){
newnodesort.removeChild (gunvar0);
newnodesort.removeChild (othervar0);
newnodesort.removeChild (dollvar02);
newnodesort.removeChild (dollvar01);
childmaker += "<div class='product-card' id = 'other'>" + othervar0.innerHTML + "</div><br/>" + "<div class='product-card' id = 'doll1'>" + dollvar01.innerHTML + "</div><br/>" + "<div class='product-card' id = 'gun1'>" + gunvar0.innerHTML + "</div><br/>" + "</div><br/>" + "<div class='product-card' id = 'doll2'>" + dollvar02.innerHTML + "</div>" ;
newnodesort.innerHTML += childmaker;
}
else if (comparevalue == "featured"){
newnodesort.removeChild (gunvar0);
newnodesort.removeChild (othervar0);
newnodesort.removeChild (dollvar02);
newnodesort.removeChild (dollvar01);
childmaker += "<div class='product-card' id = 'doll1'>" + dollvar01.innerHTML + "</div><br/>" + "<div class='product-card' id = 'gun1'>" + gunvar0.innerHTML + "</div><br/>" + "</div><br/>" + "<div class='product-card' id = 'doll2'>" + dollvar02.innerHTML + "</div><br/>" + "<div class='product-card' id = 'other'>" + othervar0.innerHTML + "</div>" ;
newnodesort.innerHTML += childmaker;
}
}
</script>
<!---
<Script>
var productmp = '<div class="product"> <h3><a href="product.html?id=<ID>"><TITLE></a></h3><a href="product.html?id=<ID>"><img src="<IMAGE>" styel="width: 400px;"></a><p>Price: $<PRICE></p></div>';
window.onload = function() {
var search_content = window.location.search.split('search=')[1];
document.querySelector('#src001').value = search_content;
if (search_content !== ''){
prodb.forEach(function.product){
if (product.title.toLowerCase().includes(search_content.toLowerCase())){
var p = productmp.replaceAll(<ID> , prodb.id);
p = p.replace(<TITLE>, prodb.pname);
p = p.replace(<IMAGE>, prodb.image);
p = p.replace(<PRICE>, prodb.price);
document.querySelector("#product-list").innerHTML += p;
}
}
}
}
</Script>
--->
</div>
</div>
</body>
</html>