-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.html
184 lines (181 loc) · 5.07 KB
/
registration.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
<!DOCTYPE html>
<head>
<title>Registration Form with User Entries</title>
</head>
<script>
const dob = document.getElementById("dob");
dob.addEventListener("change", () => validateDob(dob));
function validateDob(dob){
console.log(dob.value)
let Date1=dob.value.split("-");
let year=Date1[0];
let month=Date1[1];
let date=Date1[2];
let birthdate = new Date(year, month, date);
let today = new Date();
let currentYear= today.getFullYear();
let birthYear=birthdate.getFullYear()
let age = currentYear - birthYear;
let monthDiff = today.getMonth() - birthdate.getMonth();
if ((today.getDate() < birthdate.getDate())||monthDiff<0)
{
age--;
}
if (age<18 || age>55)
{
dob.setCustomValidity("Your age is not in between 18 and 55");
dob.reportValidity();
}
else
{
dob.setCustomValidity("");
}
}
let email=document.getElementById("email");
email.addEventListener('input',() => validate(email));
function validate(element){
if(element.validity.typeMismatch){
element.setCustomValidity("Invalid email");
element.reportValidity();
}
else{
element.setCustomValidity('');
}
}
let userform=document.getElementById('user-form');
const retriveEntries=()=>{
let entries=localStorage.getItem("entries");
if(entries){
entries=JSON.parse(entries);
}
else{
entries=[];
}
return entries;
}
let userEntries=retriveEntries();
const displayEntries=()=>{
let entries=retriveEntries();
const tableEntries=entries.map((entry)=>{
const name=`<td>${entry.name}</td>`;
const email=`<td>${entry.email}</td>`;
const password=`<td>${entry.password}</td>`;
const dob=`<td >${entry.dob}</td>`;
const accept=`<td>${entry.acceptedTermsAndCondition}</td>`;
const row=`<tr>${name} ${email} ${password} ${dob} ${accept}</tr>`;
return row;
}).join("\n");
const table=`<table border="2">
<tr>
<th>Name</th>
<th>Email</th>
<th >Password</th>
<th>Dob</th>
<th>Accepted terms?</th>
</tr>
${tableEntries}</table>`;
let details=document.getElementById("user-entries");
details.innerHTML=table;
}
const saveUserForm=(event)=>{
event.preventDefault();
const name=document.getElementById("name").value;
const email=document.getElementById("email").value;
const password=document.getElementById("password").value;
const dob=document.getElementById("dob").value;
const acceptedTermsAndCondition=document.getElementById("acceptTerms").checked;
const entry={
name,
email,
password,
dob,
acceptedTermsAndCondition
};
userEntries.push(entry);
localStorage.setItem("entries",JSON.stringify(userEntries));
displayEntries();
}
userform.addEventListener("submit",saveUserForm);
displayEntries();
</script>
<style>
.container {
width: 450px;
height: 260px;
border-radius: 9px;
background-color: blue;
border: 1px solid firebrick;
font-family: calibri;
font-size: 120%;
font-weight: bolder;
box-shadow: 6px 6px 30px rgb(99, 98, 100);
}
#title {
background-color: rgb(245, 113, 56);
color: white;
border: 1px solid firebrick;
padding-bottom: -1px;
height: 28px;
border-radius: 3px;
}
input#name,
input#email,
input#password,
input#dob {
height: 20px;
width: 100%;
}
#submit {
background-color: green;
height: 30px;
width: 100%;
color: white;
border: none;
border-radius: 5px;
font-size: 105%;
margin-top: 10px;
}
</style>
<body bgcolor="thistle">
<center>
<form id="user-form">
<fieldset class="container">
<legend id="title">Registration Form</legend>
<table cellspacing="5" cellpadding="5">
<tr>
<td><label for="name">Name </label></td>
<td><input type="text" id="name" name="nm" required /></td>
</tr>
<tr>
<td><label for="email">Email ID </label></td>
<td><input type="email" id="email" name="em" required /></td>
</tr>
<tr>
<td><label for="password">Password </label></td>
<td>
<input type="password" id="password" name="pass" required />
</td>
</tr>
<tr>
<td><label for="dob">Date Of Birth </label></td>
<td><input type="date" id="dob" name="DOB" required /></td>
</tr>
<tr>
<td align="right">
<input type="checkbox" id="acceptTerms" name="accept" />
</td>
<td><label for="acceptTerms">accept Terms & Conditions</label></td>
</tr>
<tr>
<td colspan="2" align="center">
<button type="submit" id="submit">Submit</button>
</td>
</tr>
</table>
</fieldset>
</form>
<h2>User Entries</h2>
<div id="user-entries"></div>
</center>
<script type="text/javascript" src="registration.js"></script>
</body>