-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
66 lines (61 loc) · 1.81 KB
/
index.html
File metadata and controls
66 lines (61 loc) · 1.81 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Filtered Data</title>
<style>
input {
border: 1px solid #ccc;
padding: 5px;
margin-bottom: 15px;
}
div {
border: 1px solid #ccc;
padding: 5px;
margin-bottom: 15px;
}
</style>
</head>
<body>
<div>
<input type="text" id="searchInput" placeholder="Search here.." />
<div id="filteredData"></div>
</div>
<script>
const data = [
{ Id: 1, Name: "Deepak Chaudhari", Age: 28 },
{ Id: 2, Name: "Vivek Gupta", Age: 26 },
{ Id: 3, Name: "Aarti Kumawat", Age: 32 }
];
function renderData(filteredField) {
const filteredDataContainer = document.getElementById("filteredData");
filteredDataContainer.innerHTML = "";
filteredField.forEach((item) => {
const div = document.createElement("div");
div.innerHTML = `<p>Name: ${item.Name}</p><p>Age: ${item.Age}</p>`;
filteredDataContainer.appendChild(div);
});
}
function handleSearch() {
const searchTerm = document
.getElementById("searchInput")
.value.toLowerCase();
const filteredResult = data.filter((item) => {
const filterByName = item.Name.toLowerCase();
const filterByAge = item.Age.toString();
return (
filterByName.includes(searchTerm) ||
filterByAge.includes(searchTerm)
);
});
renderData(filteredResult);
}
document
.getElementById("searchInput")
.addEventListener("input", handleSearch);
// Initial render with all data
renderData(data);
</script>
</body>
</html>