-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollegesWorld.html
More file actions
107 lines (93 loc) · 2.34 KB
/
CollegesWorld.html
File metadata and controls
107 lines (93 loc) · 2.34 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Colleges in world</title>
<style>
body{
font-family: 'Times New Roman', Times, serif;
}
h1{
text-align: center;
}
.container{
width:500px;
border:2px solid black;
border-radius: 10px;
margin:10px auto;
margin-top:20px;
}
input{
margin-left: 25px;
width:70%;
padding: 10px;
border: 1px solid gray;
font-size: 20px;
border-radius: 10px;
}
button{
text-align: center;
padding:10px;
background-color: black;
color: white;
border: none;
border-radius: 5px;
font-size: 20px;
margin: 2px;
}
#list{
margin: 10px;
}
.space{
margin:1px;
font-size: 22px;
}
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
<div class="container">
<h1>Search Colleges in Country</h1>
<input type="text" placeholder="Enter Country" />
<button>Search</button>
<ul id="list"></ul>
</div>
<script>
let btn = document.querySelector("button");
let input = document.querySelector("input");
const url = "http://universities.hipolabs.com/search?name=";
btn.addEventListener("click", async () =>{
console.log("btn was clicked");
let country = input.value;
let colArr = await getColleges(country);
// console.log(colArr);
show(colArr);
});
function show(colArr){
let list = document.querySelector("#list");
list.innerText = "";
for(col of colArr){
// console.log(col);
// console.log(col.name);
let li = document.createElement("li");
li.classList.add("space");
li.innerText = col.name;
list.appendChild(li);
}
}
async function getColleges(country){
try{
let res = await axios.get(url + country);
// console.log(res);
// console.log(res.data);
return res.data;
}
catch(e){
console.log(e);
return [];
}
}
</script>
</body>
</html>