This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
67 lines (57 loc) · 2.19 KB
/
Copy pathcode.js
File metadata and controls
67 lines (57 loc) · 2.19 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
function getData(){
//Insert all countries to the select box
fetch("/getdata")
.then(res=>res.json())
.then(data=>{
document.getElementById("table").innerHTML="";
data.forEach(element => {
//document.getElementById("table").innerHTML="";
document.getElementById("table").innerHTML+=`
<tr>
<td>${element.name}</td>
<td>${element.population}</td>
<td>${element.counter}</td>
</tr>`
});
})
.catch(err=>console.log("Error",err));
}
function getDataForCountries(){
fetch("/getdata")
.then(res=>res.json())
.then(data=>{
data.forEach(element => {
document.getElementById("counteries").innerHTML+=`<option value="${element.name}">
${element.name}
</option>`;
});
})
.catch(err=>console.log("Error",err));
}
/*db.forEach(element=>{
document.getElementById("table").innerHTML+=`
<tr>
<td>${element.name}</td>
<td>${element.population}</td>
<td>${element.counter}</td>
</tr>`
}); */
/*function getcountrydata(){
//send the county you selected to the server
let select = document.getElementById("counteries");
let country = select.options[select.selectedIndex].value;
console.log(country);
}*/
async function updateCounter(){
let counter = document.getElementById("cases").value;
let select = document.getElementById("counteries");
let country = select.options[select.selectedIndex].value;
let initParam= {
"method":"PUT",
headers: {"Content-Type": "application/json"},
body:`{"counter":"${counter}"}`
};
let res= await (fetch(`/edit/${country}`,initParam));
console.log(res);
getData();
}