-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (39 loc) · 1.46 KB
/
index.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
function submittedForm(event) {
event.preventDefault();
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
var dob = document.getElementById('dob').value;
var acceptTerms = document.getElementById('acceptTerms').checked;
var user = {
name: name,
email: email,
password: password,
dob: dob,
acceptTerms: acceptTerms ? 'Yes' : 'No'
};
var users = JSON.parse(localStorage.getItem('users')) || [];
users.push(user);
localStorage.setItem('users', JSON.stringify(users));
displayUsers();
document.getElementById('registrationForm').reset();
}
function displayUsers() {
var userList = document.getElementById('userList');
userList.innerHTML = '';
var users = JSON.parse(localStorage.getItem('users')) || [];
users.forEach(function (user) {
var row = userList.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
cell1.textContent = user.name;
cell2.textContent = user.email;
cell3.textContent = user.password;
cell4.textContent = user.dob;
cell5.textContent = user.acceptTerms? 'true':'false';
});
}
displayUsers();