4
4
< title > EMS Main Page</ title >
5
5
<!-- Use Bootstrap for styling -->
6
6
< link rel ="stylesheet " href ="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css ">
7
+ < style >
8
+ .search-container {
9
+ position : fixed;
10
+ top : 20px ;
11
+ right : 10px ;
12
+ display : flex;
13
+ align-items : center;
14
+ }
15
+
16
+ .search-container .search-icon {
17
+ cursor : pointer;
18
+ }
19
+
20
+ .search-container .search-input {
21
+ display : none;
22
+ margin-right : 20px ;
23
+ transition : width 0.5s ease-in-out;
24
+ }
25
+
26
+ .search-container .search-input .visible {
27
+ display : block;
28
+ width : 300px ;
29
+ }
30
+ </ style >
7
31
< script >
8
32
function updateEmployee ( ) {
9
33
var id = prompt ( "Enter ID:" ) ;
19
43
}
20
44
}
21
45
46
+ function toggleSearchBar ( ) {
47
+ var searchBar = document . querySelector ( '.search-input' ) ;
48
+ searchBar . classList . toggle ( 'visible' ) ;
49
+ searchBar . focus ( ) ;
50
+ }
51
+
22
52
function searchEmployee ( ) {
23
- var id = prompt ( "Enter ID:" ) ;
24
- if ( id != null ) {
25
- window . location . href = "/api/search_employee/ " + id ;
53
+ var search_query = document . querySelector ( '.search-input' ) . value ;
54
+ if ( search_query ) {
55
+ window . location . href = "/api/search_employee?search_query= " + encodeURIComponent ( search_query ) ;
26
56
}
27
57
}
28
58
</ script >
29
59
</ head >
30
60
< body >
61
+ < div class ="search-container ">
62
+ < span class ="search-icon " onclick ="toggleSearchBar() ">
63
+ < img src ="https://img.icons8.com/small/16/000000/search.png " alt ="Search ">
64
+ </ span >
65
+ < input type ="text " class ="search-input " onkeydown ="if (event.key === 'Enter') searchEmployee() " placeholder ="Search (ID, Name, Email, or Department) ">
66
+ </ div >
67
+
31
68
<!-- Create a banner -->
32
69
< div class ="jumbotron ">
33
70
< h1 class ="display-4 "> Employee Management System</ h1 >
@@ -50,11 +87,6 @@ <h1 class="display-4">Employee Management System</h1>
50
87
< button class ="btn btn-primary btn-block " onclick ="deleteEmployee() "> Delete</ button >
51
88
</ div >
52
89
</ div >
53
- < div class ="row mt-3 ">
54
- < div class ="col-md-3 ">
55
- < button class ="btn btn-primary btn-block " onclick ="searchEmployee() "> Search</ button >
56
- </ div >
57
- </ div >
58
90
</ div >
59
91
</ body >
60
92
</ html >
0 commit comments