-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidation-2.js
154 lines (138 loc) · 4.66 KB
/
Validation-2.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
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
let Edit = 0;
const prevTable = JSON.parse(localStorage.getItem("tableData"));
console.log("MapTable", prevTable);
if (prevTable) {
prevTable.map((e) => {
console.log("e", e);
const newRow = document.createElement("tr");
newRow.innerHTML = `
<td>${e.name}</td>
<td>${e.email}</td>
<td>${e.pass}</td>
<td>${e.add}</td>
<td>${e.study}</td>
<td>${e.gender}</td>
<td> <img src='${e.file}'/> </td>
<td>${e.date}</td>
<td><button class='btn text-white bg-primary'onclick='editRow(this)'>Edit</button></td>
<td><button class='btn text-white bg-danger'onclick='deleteRow(this)'>Delete</button></td>
`;
console.log("newRow", newRow);
document.getElementById("tableData").appendChild(newRow);
});
}
function addData() {
const name = document.getElementById("Name").value;
const email = document.getElementById("Email").value;
const password = document.getElementById("Password").value;
const address = document.getElementById("Address").value;
const study = document.getElementById("Study").value;
const gender = document.getElementById("Gender").value;
const file = document.getElementById("File").value;
const date = document.getElementById("Date").value;
if (Edit == 0) {
const newRow = document.createElement("tr");
const newFormData = {
name: name,
email: email,
pass: password,
add: address,
study: study,
gender: gender,
file: file,
date: date,
};
console.log(newFormData);
const prevData = JSON.parse(localStorage.getItem("tableData"));
let TableData;
if (prevData) {
TableData = [...prevData, newFormData];
} else {
TableData = [newFormData];
}
newRow.innerHTML = `
<td>${name}</td>
<td>${email}</td>
<td>${password}</td>
<td>${address}</td>
<td>${study}</td>
<td>${gender}</td>
<td>${file}</td>
<td>${date}</td>
<td><button class='btn text-white bg-primary'onclick='editRow(this)'>Edit</button></td>
<td><button class='btn text-white bg-danger'onclick='deleteRow(this)'>Delete</button></td>
`;
localStorage.setItem("tableData", JSON.stringify(TableData));
document.getElementById("tableData").appendChild(newRow);
console.log("newRow", newRow);
} else {
const row = document.getElementById("tableData").rows[Edit];
row.cells[0].textContent = name;
row.cells[1].textContent = email;
row.cells[2].textContent = password;
row.cells[3].textContent = address;
row.cells[4].textContent = study;
row.cells[5].textContent = gender;
EditData = 0;
console.log("row", row.cells);
}
document.getElementById("Name").value = " ";
document.getElementById("Email").value = " ";
document.getElementById("Password").value = "";
document.getElementById("Address").value = " ";
document.getElementById("Study").value = " ";
document.getElementById("Gender").value = "";
document.getElementById("File").value = " ";
document.getElementById("Date").value = " ";
}
function editRow(button) {
const row = button.parentNode.parentNode;
const name = row.cells[0].textContent;
const email = row.cells[1].textContent;
const pass = row.cells[2].textContent;
const address = row.cells[3].textContent;
const study = row.cells[4].textContent;
const gender = row.cells[5].textContent;
const file = row.cells[6].textContent;
const date = row.cells[7].textContent;
document.getElementById("Name").value = name;
document.getElementById("Email").value = email;
document.getElementById("Password").value = pass;
document.getElementById("Address").value = address;
document.getElementById("Study").value = study;
document.getElementById("Gender").value = gender;
document.getElementById("File").value = file;
document.getElementById("Date").value = date;
Edit = row.rowIndex;
console.log("edit Row");
}
function deleteRow(button) {
const row = button.parentNode.parentNode;
row.parentNode.removeChild(row);
console.log("delete");
}
// Form Buttons Disable Andable
function checkForm() {
var input = document.getElementsByClassName("form-control");
var btn = document.getElementById("form-submit");
var btn2 = document.getElementById("form-reset");
let valid = true;
let reset = true;
for (let i = 0; i < input.length; i++) {
const changeInput = input[i];
if (changeInput.value == 0 || changeInput.value == null) {
valid = false;
break;
}
}
for (let i = 0; i < input.length; i++) {
const resetInput = input[i];
if (resetInput.value === 0 || resetInput.value === null) {
reset = false;
break;
}
}
btn.disabled = !valid;
btn2.disabled = !reset;
console.log("Sumbit", valid);
}