-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
138 lines (99 loc) · 3.38 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
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
// const studentForm = document.getElementById("student-form");
// const studentTable = document.getElementById("student-table");
// function addStudentToTable(student) {
// const row = studentTable.insertRow();
// row.innerHTML = `
// <td>${student.name}</td>
// <td>${student.dob}</td>
// <td>${student.gender}</td>
// <td>${student.phone}</td>
// <td>${student.grade}</td>
// `;
// }
// studentForm.addEventListener("submit", function(event) {
// event.preventDefault();
// const name = document.getElementById("name").value;
// const dob = document.getElementById("dob").value;
// const gender = document.getElementById("gender").value;
// const phone = document.getElementById("phone").value;
// const grade = document.getElementById("grade").value;
// const student = {
// name: name,
// dob: dob,
// gender: gender,
// phone: phone,
// grade: grade
// };
// addStudentToTable(student);
// studentForm.reset();
// });
//constructor Task
let arrData=[];
if(localStorage.arrData != null){
arrData=JSON.parse(localStorage.arrData);
render();
}
let footer00=document.getElementById("myDIV");
let userName;
let userDOB;
let userGender;
let userNumber;
let userGrade;
let userMajor;
let userImg;
let DataCollected=document.getElementById("datasub");
DataCollected.addEventListener("submit",function(event){
userName=event.target.username.value;
userDOB=event.target.userDOB.value;
userGender=event.target.usergender.value;
userNumber=event.target.usernumber.value;
userGrade=event.target.usergrade.value;
userMajor=event.target.usermajor.value;
userImg=event.target.userimg.value;
DataCollected.reset();
let student = new Person(userName,userDOB ,userGender,userNumber,userGrade,userMajor,userImg);
arrData.push(student);
localStorage.setItem('arrData',JSON.stringify(arrData) );
render();
});
function Person(userName,userDOB ,userGender,userNumber,userGrade,userMajor,userImg) {
this.userName = userName;
this.userDOB = userDOB;
this.userGender = userGender;
this.userNumber = userNumber;
this.userGrade = userGrade;
this.userMajor = userMajor;
this.userImg = userImg;
}
//-------------show data-----------------//
function render(){
for(let i=0;i<arrData.length;i++){
let sdcard= document.getElementById("student_card");
let divContainer = document.createElement('div');
let img0 = document.createElement('img');
img0.src=`${arrData[i].userImg}`;
let ul = document.createElement("ul");
let li1= document.createElement("li");
li1.textContent=`Name: ${arrData[i].userName}`;
let li2= document.createElement("li");
li2.textContent=`Gender: ${arrData[i].userGender}`;
let li3= document.createElement("li");
li3.textContent=`Number: ${arrData[i].userNumber}`;
let li4= document.createElement("li");
li4.textContent=`Grade: ${arrData[i].userGrade}`;
let li5= document.createElement("li");
li5.textContent=`Major: ${arrData[i].userMajor}`;
ul.appendChild(li1);
ul.appendChild(li2);
ul.appendChild(li3);
ul.appendChild(li4);
ul.appendChild(li5);
divContainer.appendChild(img0);
divContainer.appendChild(ul);
sdcard.appendChild(divContainer);
}
}
window.addEventListener('load', () => {
localStorage.clear(); // clear local storage
document.getElementById('myForm').reset(); // reset form
});