-
Notifications
You must be signed in to change notification settings - Fork 0
/
todolistindex.html
155 lines (115 loc) · 4.85 KB
/
todolistindex.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>To Do List</title>
</head>
<body>
<header class="bg-success text-white p-5">
<div class="container" style="background-color: gold;">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<font face="courier new" size="11" color="black">
<strong>ToDo - List</strong>
</font>
</div>
</div>
</div>
</header>
<div class="container mt-3" style="background-color: lightgoldenrodyellow;">
<h2>Add Items</h2>
<label id="lblsuccess" class="text-success" style="display: none;">
</label>
<form id="addForm">
<div class="row">
<div class="col-lg-7 col-md-7 col-sm-7">
<input type="text" onkeyup="toggleButton(this, 'submit')" class="form-control" id="item">
</div>
<div class="col-lg-5 col-md-5 col-sm-5">
<input type="submit" class="btn btn-dark" id="submit" value="Submit" disabled>
</div>
</div>
</form>
<h3 class="mt-4">Tasks</h3>
<form id="addForm">
<ul class="list-group" id="items"></ul>
</form>
</div>
</body>
</html>
<script>
window.onload = () => {
const form1 = document.querySelector("#addForm");
let items = document.getElementById("items");
let submit = document.getElementById("submit");
let editItem = null;
form1.addEventListener("submit", addItem);
items.addEventListener("click", removeItem);
};
function addItem(e) {
e.preventDefault();
if (submit.value != "Submit") {
console.log("Hello");
editItem.target.parentNode.childNodes[0].data
= document.getElementById("item").value;
submit.value = "Submit";
document.getElementById("item").value = "";
document.getElementById("lblsuccess").innerHTML
= "Text edited successfully";
document.getElementById("lblsuccess")
.style.display = "block";
setTimeout(function() {
document.getElementById("lblsuccess")
.style.display = "none";
}, 3000);
return false;
}
let newItem = document.getElementById("item").value;
if (newItem.trim() == "" || newItem.trim() == null)
return false;
else
document.getElementById("item").value = "";
let li = document.createElement("li");
li.className = "list-group-item";
let deleteButton = document.createElement("button");
deleteButton.className =
"btn-danger btn btn-sm float-right delete";
deleteButton.appendChild(document.createTextNode("Delete"));
let editButton = document.createElement("button");
editButton.className =
"btn-success btn btn-sm float-right edit";
editButton.appendChild(document.createTextNode("Edit"));
li.appendChild(document.createTextNode(newItem));
li.appendChild(deleteButton);
li.appendChild(editButton);
items.appendChild(li);
}
function removeItem(e) {
e.preventDefault();
if (e.target.classList.contains("delete")) {
if (confirm("Are you Sure?")) {
let li = e.target.parentNode;
items.removeChild(li);
document.getElementById("lblsuccess").innerHTML
= "Text deleted successfully";
document.getElementById("lblsuccess")
.style.display = "block";
setTimeout(function() {
document.getElementById("lblsuccess")
.style.display = "none";
}, 3000);
}
}
if (e.target.classList.contains("edit")) {
document.getElementById("item").value =
e.target.parentNode.childNodes[0].data;
submit.value = "EDIT";
editItem = e;
}
}
function toggleButton(ref, btnID) {
document.getElementById(btnID).disabled = false;
}
</script>