-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCD.html
95 lines (84 loc) · 3.82 KB
/
CD.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- bootstrap cdn -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<!-- bootstrap links -->
<link rel="stylesheet" href="./bootstrap-5.0.2-dist/css/bootstrap.min.css">
<script src="./bootstrap-5.0.2-dist/js/bootstrap.min.js"></script>
<!-- jquery link -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<!-- font awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<!-- custom-css -->
<link rel="stylesheet" href="/snippets.css">
<link rel="stylesheet" href="product.css">
<!-- custom js -->
<script src="../snippets.js"></script>
</head>
<body>
<!-- nav bar -->
<header id="NAV"></header>
<!-- Add a search bar -->
<div class="container " id="set">
<div class="row">
<div class="col-lg-4">
<div>
<label for="searchInput " class="form-label">Search</label>
<input type="text" class="form-control" id="searchInput" aria-describedby="searchHelp" placeholder="search for brand">
</div>
</div>
</div>
</div>
<!-- card -->
<div class="container" id="set">
<div class="row justify-content-evenly" id="card"></div>
</div>
<!-- footer -->
<footer class="bg-light text-dark p-5" id="FOOT"></footer>
<script>
$(document).ready(function () {
$.ajax({
url: "CD.json",
dataType: "json",
type: "get",
success: function (data) {
function displayProducts(data) {
let x = "";
$.each(data, function (key, value) {
x += `
<div class="col-lg-3 col-md-6 col-sm-6 mb-5">
<div class="card">
<img src="${value.image}" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">${value.name}</h5>
<p class="card-text"><small class="text-muted">$${value.price}</small></p>
<a href="detCD.html?id=${value.id}" class="btn btn-navy">Detail</a>
</div>
</div>
</div>
`;
});
$("#card").html(x);
}
displayProducts(data);
// Filter products based on user input
$("#searchInput").on("input", function () {
let searchTerm = $(this).val().toLowerCase();
let filteredData = data.filter(function (product) {
return product.name.toLowerCase().includes(searchTerm);
});
displayProducts(filteredData);
});
}
});
});
</script>
</body>
</html>