-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.js
66 lines (56 loc) · 2.13 KB
/
list.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
$(function ()
{
try
{
let num= [];
$("#tb").on("change", ":checkbox", function ()
{
var checkstatus=this.checked;
let j=num.indexOf(this.id);
let Aitem=this.id;
var p= new Promise(function (resolve, reject) {
if(checkstatus === true)
{
if(j==-1){
num.push(Aitem);
}
}
else {
if(j!=-1){
num.splice(Aitem,1);
}
}
if (num.length==5) {
resolve("Congratulations! 5 Tasks have been successfully completed!");
}
});
p.then(function (ex)
{ alert(ex);
num=[];
});
});
var tb= document.getElementById("tb");
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var List = JSON.parse(this.responseText);
var it = List;
var op = "<caption></caption><tr><th>USER ID</th><th>ID</th><th>TITLE</th><th>STATUS</th></tr>";
for (let i = 0; i < it.length; i++) {
op += "<tr>";
op += "<td>" + it[i].userId + "</td>";
op += "<td>" + it[i].id + "</td>";
op += "<td>" + it[i].title + "</td>";
op += "<td><input type='checkbox' id='checkbox"+ it[i].id +"'" + ((it[i].completed == true) ? 'checked disabled' : '') + " ></td>";
}
tb.innerHTML = op;
}
}
xhttp.open("GET", "https://jsonplaceholder.typicode.com/todos", true);
xhttp.send();
}
catch (e) {
document.getElementById("listdiv").innerHTML = e;
}
$(".logout").click(function(){location.replace("index.html");});
});