-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetails.html
More file actions
179 lines (168 loc) · 6.47 KB
/
details.html
File metadata and controls
179 lines (168 loc) · 6.47 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
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
<html>
<head>
<meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1">
<title>Employee Search</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body, html {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
justify-content: center;
display:flex;
}
.container-fluid{
border-radius:25px;
background:transparent;
margin-top:100px;
padding-top:5px;
padding-bottom:5px;
padding-left:40px;
padding-right:40px;
width:fit -content;
border: 1px solid white;
}
.col-auto{
color: white;
font-size: 15px;
margin: 10px;
justify-content: center;
}
body{
background-image: url('https://res.cloudinary.com/djm2h1vqr/image/upload/v1719405949/Untitled_design_sdnkq3.png');
background-size: cover;
background-position: center;
}
.submitbtn{
cursor: pointer;
border: 1px solid whitesmoke;
background-color: transparent;
color: white;
font-size: large;
}
.button-container{
display:flex;
justify-content: center;
}
.row-justify-content {
display: flex;
justify-content: space-around;}
.row-justify-content label,
.row-justify-content input {
margin: 0 10px ;
margin-bottom: 5px;
display:block;
}
.form-control{
border-radius: 0px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 20px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
#data-output{
color: white;
}
</style>
</head>
<body>
<form id="searchForm">
<div class="container-fluid">
<header><div class="navbar"></div></header>
<div class="row justify-content-center">
<div class="col-auto text-center">
<label for="idsearch">Search</label>
<input type="text" name="search" id="idsearch" class="form-control" placeholder="Enter Employee ID">
</div>
</div>
<div class="row justify-content-center">
<div class="col-auto text-center">
<button type="submit" class="submitbtn">Submit</button>
</div>
</div>
</form>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Position</th>
<th>Department</th>
<th>Email</th>
</tr>
</thead>
<tbody id="data-output">
</tbody>
</table>
</div>
<script>
const nav = document.querySelector('.navbar')
fetch('navbar.html')
.then(res=>res.text())
.then(data=>{
nav.innerHTML=data;
})
</script>
<script>
const searchForm = document.getElementById('searchForm');
searchForm.addEventListener('submit', function(e) {
e.preventDefault();
const searchInput = document.getElementById('idsearch').value.trim();
if (!searchInput) {
alert('Please enter an Employee ID to search.');
return;
}
const idToSearch = parseInt(searchInput);
if (isNaN(idToSearch)) {
alert('Please enter a valid number for Employee ID.');
return;
}
fetch('details.json')
.then(response => response.json())
.then(data => {
const employees = data.employees;
const employee = employees.find(emp => emp.id === idToSearch);
if (employee) {
displayEmployee(employee);
} else {
displayNotFound();
}
})
.catch(error => console.error('Error fetching JSON data:', error));
});
// Display employee data in the table
function displayEmployee(employee) {
const row = `
<tr>
<td>${employee.id}</td>
<td>${employee.name}</td>
<td>${employee.position}</td>
<td>${employee.department}</td>
<td>${employee.email}</td>
</tr>
`;
document.getElementById('data-output').innerHTML = row;
}
// Display not found message in the table
function displayNotFound() {
const row = `
<tr>
<td colspan="5">Employee not found</td>
</tr>
`;
document.getElementById('data-output').innerHTML = row;
}
</script>
</body>
</html>