-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch.js
51 lines (46 loc) · 1.51 KB
/
search.js
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
var Search = function(){
var Reg_id = document.getElementById("Reg_id");
var Name = document.getElementById("Name");
Reg_id.addEventListener("input", function(event){
if(Reg_id.value){
Name.readOnly = true;
}
else{
Name.readOnly = false;
}
});
Name.addEventListener("input", function(event){
if(Name.value){
Reg_id.readOnly = true;
}
else{
Reg_id.readOnly = false;
}
});
var search = document.getElementById("Search");
search.addEventListener("click", function(event){
var http = new XMLHttpRequest();
http.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
var arr = JSON.parse(this.responseText);
//console.log(arr);
if(arr.length!=0){
//console.log(arr.length);
display(arr);
}
else{
document.getElementsByClassName('left')[0].innerHTML=`<div class="form"><h1 id="stadd">Student not found.</h1></div>`;
}
}
}
if(Reg_id.value){
http.open("GET", `http://localhost:4000/api/reg_id/${Reg_id.value}`, true);
http.send();
}
else if(Name.value){
http.open("GET", `http://localhost:4000/api/name/${Name.value}`, true);
http.send();
}
});
}
Search();