-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
157 lines (143 loc) · 5.59 KB
/
index.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<nav class="navbar navbar-expand-lg bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">TODOs LIST</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup"
aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-link active" aria-current="page" href="#">Home</a>
<a class="nav-link" href="#">Timeline</a>
<a class="nav-link" href="#">Locations</a>
<a class="nav-link disabled">Exercises</a>
</div>
</div>
</div>
</nav>
<div class="container">
<h2 class="text-center">TODOs LIST</h2>
<div class="form-group px-4">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" aria-describedby="emailHelp">
<small id="emailHelp" class="form-text text-muted">Ekta title add koro bhai gula</small>
</div>
<div class="form-group px-4">
<label for="description">Description</label>
<textarea class="form-control" id="description" rows="3"></textarea>
</div>
<div class="px-4">
<a href="https://electro1212.github.io/Todo_list_javaScript/"><button type="submit" id="add" class="btn btn-primary">Add to list</button></a>
<button type="submit" id="clear" class="btn btn-primary" onclick="clearStorage()">Clear List</button>
</div>
<div id="item" class="px-4">
<h2>Your Items</h2>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Item Title</th>
<th scope="col">Item Description</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
</table>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js" integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU="
crossorigin="anonymous"></script>
<script>
function getAndUpdate() {
console.log("updating list...")
tit = document.getElementById('title').value;
desc = document.getElementById('description').value;
if (localStorage.getItem('itemJson') == null) {
itemJsonArray = [];
itemJsonArray.push([tit, desc]);
localStorage.setItem('itemJson', JSON.stringify(itemJsonArray))
}
else {
itemJsonArrayStr = localStorage.getItem('itemJson')
itemJsonArray = JSON.parse(itemJsonArrayStr);
itemJsonArray.push([tit, desc]);
localStorage.setItem('itemJson', JSON.stringify(itemJsonArray))
}
update();
}
function update() {
console.log("updating list...")
tit = document.getElementById('title').value;
desc = document.getElementById('description').value;
if (localStorage.getItem('itemJson') == null) {
itemJsonArray = [];
localStorage.setItem('itemJson', JSON.stringify(itemJsonArray))
}
else {
itemJsonArrayStr = localStorage.getItem('itemJson')
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 btn-sm btn-primary" onclick="deleted(${index})">Delete</button></td>
</tr>
`;
});
tableBody.innerHTML = str;
}
add = document.getElementById("add");
add.addEventListener("click", getAndUpdate);
update();
function deleted(itemIndex) {
console.log("delete", itemIndex);
itemJsonArrayStr = localStorage.getItem('itemJson')
itemJsonArray = JSON.parse(itemJsonArrayStr);
//delete item index element from the array
itemJsonArray.splice(itemIndex, 1);
localStorage.setItem('itemJson', JSON.stringify(itemJsonArray))
update();
}
function clearStorage() {
if (confirm("Do you really want to clear all your data?")) {
}
else {
return false;
}
console.log('clearing the storage...');
localStorage.clear();
update();
}
</script>
</body>
</html>