-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.html
334 lines (328 loc) · 11.2 KB
/
data.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--Title-->
<title>Simple Student Record</title>
<!-- CSS File-->
<style>
body {
background-image: url('1.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
body > table{
width: 100%;
}
table{
border-collapse: collapse;
text-align: center;
}
table.list{
width:100%;
text-align: center;
}
table.list td{
text-align: center;
}
td, th {
border: 1px solid #191818;
text-align: left;
padding: 8px;
}
tr:nth-child(even),table.list thead>tr {
background-color: #5ba4a38f;
}
input[type=text], input[type=number] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit]{
width: 30%;
background-color: #ddd;
color: #000;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
form{
background-image: url('1.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover; padding: 10px;
}
form div.form-action-buttons{
text-align: center;
}
a{
cursor: pointer;
text-decoration: underline;
color: #0000ee;
margin-right: 4px;
}
label.validation-error{
color: red;
margin-left: 5px;
}
.hide{
display:none;
}
.button {
background-color: #4CAF50; /* Green */
border: none;
color: black;
background: linear-gradient(45deg, #bcb6b6, #a2141400);
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
transition-duration: 0.4s;
cursor: pointer;
}
</style>
</head>
<body>
<CENTER><h2>Simple Student Records</h2>
</CENTER>
<!--Table-->
<table>
<!--Row-1-->
<tr>
<!--Column-1-->
<td>
<!--Form-->
<form onsubmit="event.preventDefault();onFormSubmit();" autocomplete="off">
<h3>Student Form</h3>
<!--div-1-->
<div>
<label>Full Name</label>
<!--Validation Error-->
<label class="validation-error hide" id="userNamevalidationError">This field is required</label>
<!--Input User Name-->
<input type="text" name="userName" id="userName" placeholder="Enter the user Name">
</div>
<!--div-2-->
<div>
<label>Rollno</label>
<!--Validation Error-->
<label class="validation-error hide" id="rollNovalidationError" >This field is required</label>
<!--Input Roll No-->
<input type="text" name="rollNo" id="rollNo" placeholder="Enter the Roll number">
</div>
<!--div-3-->
<div>
<label>Student Class</label>
<!--Validation Error-->
<label class="validation-error hide" id="stdClassvalidationError">This field is required</label>
<!--Input Student Class-->
<input type="text" name="stdClass" id="stdClass" placeholder="Enter the Student Class">
</div>
<!--div-4-->
<div>
<label>Total Subject</label>
<!--Validation Error-->
<label class="validation-error hide" id="tsubvalidationError">This field is required</label>
<!--Input Total Subject-->
<input type="number" name="tsub" id="tsub" placeholder="Enter the Total Subjects">
</div>
<!--div-5-->
<div>
<label>Age</label>
<!--Validation Error-->
<label class="validation-error hide" id="agevalidationError">This field is required</label>
<!--Input Age-->
<input type="number" name="age" id="age" placeholder="Enter the Age">
</div>
<!--div-6-->
<div class="form-action-buttons">
<!--Input Button-->
<input type="submit" value="Submit">
</div>
</form>
</td>
<!--Column-2-->
<td>
<!--Nested Table-->
<table class="list" id="stdlist" style="background-color: #f9f9ff82;">
<!--Table Head-->
<thead>
<!--Row-2-->
<tr>
<th>Full Name</th>
<th> Roll no</th>
<th>Class</th>
<th>Total Subject</th>
<th>Age</th>
<th>Action</th>
</tr>
</thead>
<!--Table Body-->
<tbody>
</tbody>
</table>
</td>
</tr>
</table>
<!-- dcgx -->
<script>
var selectedRow = null
// Form Submit Function
function onFormSubmit() {
// check validity
if (validate()) {
// store user data
var formData = readFormData();
// check empty row
if (selectedRow == null)
{
// Insert New User Record
insertNewRecord(formData);
}
else
{
// Update New User Record
updateRecord(formData);
}
// Reset Input Values
resetForm();
}
}
// Get Values From Form
function readFormData() {
var formData = {};
// Get Values From Input
formData["userName"] = document.getElementById("userName").value;
formData["rollNo"] = document.getElementById("rollNo").value;
formData["stdClass"] = document.getElementById("stdClass").value;
formData["tsub"] = document.getElementById("tsub").value;
formData["age"] = document.getElementById("age").value;
// return Form Data
return formData;
}
// Insert New User Record
function insertNewRecord(data) {
var table = document.getElementById("stdlist").getElementsByTagName('tbody')[0];
var newRow = table.insertRow(table.length);
cell1 = newRow.insertCell(0);
cell1.innerHTML = data.userName;
cell2 = newRow.insertCell(1);
cell2.innerHTML = data.rollNo;
cell3 = newRow.insertCell(2);
cell3.innerHTML = data.stdClass;
cell4 = newRow.insertCell(3);
cell4.innerHTML = data.tsub;
cell5 = newRow.insertCell(4);
cell5.innerHTML = data.age;
cell5 = newRow.insertCell(5);
cell5.innerHTML = `<a onClick="onEdit(this)">Edit</a>
<a onClick="onDelete(this)">Delete</a>`;
}
// Reset Function
function resetForm() {
document.getElementById("userName").value = "";
document.getElementById("rollNo").value = "";
document.getElementById("stdClass").value = "";
document.getElementById("tsub").value = "";
document.getElementById("age").value = "";
selectedRow = null;
}
// Edit Function
function onEdit(td) {
selectedRow = td.parentElement.parentElement;
document.getElementById("userName").value = selectedRow.cells[0].innerHTML;
document.getElementById("rollNo").value = selectedRow.cells[1].innerHTML;
document.getElementById("stdClass").value = selectedRow.cells[2].innerHTML;
document.getElementById("tsub").value = selectedRow.cells[3].innerHTML;
document.getElementById("age").value = selectedRow.cells[4].innerHTML;
}
// Update Record
function updateRecord(formData) {
selectedRow.cells[0].innerHTML = formData.userName;
selectedRow.cells[1].innerHTML = formData.rollNo;
selectedRow.cells[2].innerHTML = formData.stdClass;
selectedRow.cells[3].innerHTML = formData.tsub;
selectedRow.cells[4].innerHTML = formData.age;
}
// Delete Function
function onDelete(td) {
if (confirm('Are you sure to delete this record ?')) {
row = td.parentElement.parentElement;
document.getElementById("stdlist").deleteRow(row.rowIndex);
resetForm();
}
}
// Check User validation
function validate() {
isValid = true;
// userName validation
if (document.getElementById("userName").value == "") {
isValid = false;
document.getElementById("userNamevalidationError").classList.remove("hide");
} else {
isValid = true;
if (!document.getElementById("userNamevalidationError").classList.contains("hide"))
{
document.getElementById("userNamevalidationError").classList.add("hide");
}
}
// Roll No validation
if (document.getElementById("rollNo").value == "") {
isValid = false;
document.getElementById("rollNovalidationError").classList.remove("hide");
} else {
isValid = true;
if (!document.getElementById("rollNovalidationError").classList.contains("hide"))
{
document.getElementById("rollNovalidationError").classList.add("hide");
}
}
// Std class validation
if (document.getElementById("stdClass").value == "") {
isValid = false;
document.getElementById("stdClassvalidationError").classList.remove("hide");
} else {
isValid = true;
if (!document.getElementById("stdClassvalidationError").classList.contains("hide"))
{
document.getElementById("stdClassvalidationError").classList.add("hide");
}
}
// Tsub validation
if (document.getElementById("tsub").value == "") {
isValid = false;
document.getElementById("tsubvalidationError").classList.remove("hide");
} else {
isValid = true;
if (!document.getElementById("tsubvalidationError").classList.contains("hide"))
{
document.getElementById("tsubvalidationError").classList.add("hide");
}
}
// Age validation
if (document.getElementById("age").value == "") {
isValid = false;
document.getElementById("agevalidationError").classList.remove("hide");
} else {
isValid = true;
if (!document.getElementById("agevalidationError").classList.contains("hide"))
{
document.getElementById("agevalidationError").classList.add("hide");
}
}
return isValid;
}
</script>
</body>