-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
77 lines (69 loc) · 1.78 KB
/
script.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
67
68
69
70
71
72
73
74
75
76
77
let btn = document.getElementById("addbtn");
seenote();
btn.addEventListener("click", function (e) {
let txt = document.getElementById("addtxt");
let title = document.getElementById("addtitle");
if ($("#addtitle").val().length <= 5) {
alert("Title Should be more than 5 chacters");
return false;
}
if ($("#addtxt").val().length <= 5) {
alert("Description Should be more than 5 chacters");
return false;
}
let R = localStorage.getItem("R");
console.log(R);
if (R == null) {
newObj = [];
} else {
newObj = JSON.parse(R);
}
let myObj = {
title: title.value,
txt: txt.value,
};
newObj.push(myObj);
localStorage.setItem("R", JSON.stringify(newObj));
txt.value = " ";
title.value = " ";
seenote();
});
function seenote() {
let R = localStorage.getItem("R");
//console.log(R)
if (R == null) {
newObj = [];
} else {
newObj = JSON.parse(R);
}
html = " ";
newObj.forEach(function (element, index) {
html += ` <div class="notecard card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title jsTitle">${element.title} </h5>
<hr>
<p class="card-text jsDescription">${element.txt}</p>
<button href="#" id=${index} onclick='D(this.id)' class="btn btn-primary">DELETE</button>
</div>
</div>`;
});
let allnote = document.getElementById("allnote");
if (html != 0) {
allnote.innerHTML = html;
} else {
allnote.innerHTML = "Enter your ToDoList : )";
}
}
function D(index) {
let R = localStorage.getItem("R");
//console.log(R)
if (R == null) {
newObj = [];
} else {
newObj = JSON.parse(R);
}
console.log(newObj, index);
newObj.splice(index, 1);
localStorage.setItem("R", JSON.stringify(newObj));
seenote();
}