-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
124 lines (101 loc) · 3.11 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
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
let username = document.getElementById("name"),
email = document.getElementById("email"),
password = document.getElementById("password"),
term = document.getElementById("terms"),
dob = document.getElementById("dob");
dob.addEventListener('input',(event)=>{
event.preventDefault();
let age = new Date().getFullYear() - new Date(dob.value).getFullYear();
function check(){
if(age < 18 || age>55){
return false;
}else{
return true;
}
}
if(!check()){
dob.setCustomValidity("age shuld be between 18 to 55");
dob.reportValidity();
}else{
dob.setCustomValidity('');
}
});
email.addEventListener("input", (e) => {
let format_email = !(email.value.includes("@") && email.value.includes("."));
if(format_email){
email.setCustomValidity("please use valid mail");
email.reportValidity();
}
else{
email.setCustomValidity("");
}
});
term.addEventListener("input", (event) => {
let ag = !term.checked;
event.preventDefault();
if(ag){
term.setCustomValidity('PLEASE agree term and condition');
term.reportValidity();
}else{
term.setCustomValidity('');
}
});
function inner(){
let check = false;
if(term.checked){
check = true;
}
let main = {
name: username.value,
email: email.value,
password: password.value,
dob: dob.value,
checked: check
}
return main;
}
form.addEventListener("submit", (event) => {
let agree= !term.checked;
event.preventDefault();
if (!agree) {
let main = inner();
select.push(main);
localStorage.setItem("select", JSON.stringify(select));
}
outcome();
});
window.onload = (event) => {
outcome();
};
let select = [];
function inputitem(){
let main = localStorage.getItem("select");
if(main){
select = JSON.parse(main);
}else{
select = [];
}
return select;
}
select = inputitem();
function outcome(){
let table =document.getElementById("table")
let a = select;
let str = `<tr>
<th>Name</th>
<th>Email</th>
<th>Password</th>
<th>Dob</th>
<th>Accepted terms?</th>
</tr>\n`;
for(let i=0;i<a.length;i++){
str += `<tr>
<td>${a[i].name}</td>
<td>${a[i].email}</td>
<td>${a[i].password}</td>
<td>${a[i].dob}</td>
<td>${a[i].checked}</td>
</tr>\n`;
}
table.innerHTML = str;
}