forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
108 lines (76 loc) · 2.33 KB
/
app.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
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
function add() {
var data = document.getElementById('text').value;
if (data === "") {
alert("Nothing To Add!", "", "warning");
}
else {
var div = document.createElement("div")
div.setAttribute('class', 'input-group p-3')
var inp = document.createElement("input");
inp.value = data
inp.setAttribute('class', 'form-control bg-darl')
inp.setAttribute('disabled', 'disabled')
// inp.setAttribute('autofocus', 'autofocus')
var editBtn = document.createElement('button')
var edittext = document.createTextNode('Edit')
editBtn.appendChild(edittext)
editBtn.setAttribute('class', 'btn btn-success')
editBtn.setAttribute('onclick', 'edit(this.previousSibling)')
var delBtn = document.createElement('button')
var deltext = document.createTextNode('Delete')
delBtn.appendChild(deltext)
delBtn.setAttribute('class', 'btn btn-outline-dark')
delBtn.setAttribute('onclick', 'del(this)')
div.appendChild(inp)
div.appendChild(editBtn)
div.appendChild(delBtn)
main.appendChild(div)
document.getElementById('text').value = "";
alert("Successfully Added!", "", "success");
}
}
function del(a) {
swal({
title: "Are you sure?",
text: "",
icon: "warning",
buttons: true,
buttons: ["No", "Yes"],
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
a.parentNode.remove();
}
});
}
function edit(inputdata) {
var check = inputdata.nextSibling.innerText
if (check === "Edit") {
console.log(inputdata)
inputdata.disabled = false;
inputdata.focus();
inputdata.nextSibling.innerText = "Update"
console.log(inputdata.nextSibling.innerText = "Update")
}
else if (check === "Update") {
inputdata.disabled = true;
inputdata.nextSibling.innerText = "Edit"
swal("Successfully Updated!", "", "success");
}
else {
alert("Some Error Occur")
}
}
// alertify.confirm("This is a confirm dialog.",
// function () {
// alertify.success('Ok');
// },
// function () {
// alertify.error('Cancel');
// });
function enter(code) {
if (code.keyCode === 13) {
add()
}
}