-
Notifications
You must be signed in to change notification settings - Fork 0
/
project2.html
125 lines (112 loc) · 4.99 KB
/
project2.html
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<title>To-Do list!</title>
</head>
<body>
<div class="container">
<h2 class="text-center">TODOs list</h2>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Title</label>
<input type="email" class="form-control" id="title" aria-describedby="emailHelp">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="description" rows="3"></textarea>
</div>
<button type="submit" id="add" class="btn-sm btn-primary">Add to list</button>
<button type="submit" id="clear" onclick="clearit()" class="btn-sm btn-primary">clear list</button>
<div id="items" class="m-3">
<h2>Your items</h2>
<table class="table">
<thead>
<tr>
<th scope="col">S.No</th>
<th scope="col">title</th>
<th scope="col">descripton</th>
<th scope="col">action</th>
</tr>
</thead>
<tbody id="tablebody">
<tr>
<th scope="row">1</th>
<td>balance</td>
<td>you need to balance both the lives</td>
<td><button class="btn bg-warning text-center">delete</button></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous"></script>
<script>
function getAndupdate(){
console.log("updating");
titl = document.getElementById("title").value;
desc = document.getElementById("description").value;
if (localStorage.getItem('itemsJson')==null){
itemJsonArray = [];
itemJsonArray.push([titl,desc]);
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray))
}
else{
itemJsonArraystr = localStorage.getItem('itemsJson')
itemJsonArray = JSON.parse(itemJsonArraystr);
itemJsonArray.push([titl,desc]);
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray))
}
update();
}
function update(){
if (localStorage.getItem('itemsJson')==null){
itemJsonArray = [];
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray))
}
else{
itemJsonArraystr = localStorage.getItem('itemsJson')
itemJsonArray = JSON.parse(itemJsonArraystr);
}
//populate the table
let tablebody=document.getElementById('tablebody');
let str="";
itemJsonArray.forEach((element, index) => {
str +=`
<tr>
<th scope="row">${index+1}</th>
<td>${element[0]}</td>
<td>${element[1]}</td>
<td><button class="btn bg-warning text-center" onclick="dlt(${index})">delete</button></td>
</tr>`;
});
tablebody.innerHTML = str;
}
add = document.getElementById("add");
add.addEventListener("click", getAndupdate);
update();
function dlt(itemIndex){
console.log("Delete",itemIndex);
itemJsonArraystr = localStorage.getItem('itemsJson')
itemJsonArray = JSON.parse(itemJsonArraystr);
itemJsonArray.splice(itemIndex, 1);
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray));
update();
}
function clearit(){
if(confirm('do you want to delete the entire list?')){
localStorage.clear();
update();
}
}
</script>
</body>
</html>