-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.html
200 lines (176 loc) · 6.76 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!doctype html>
<!--
to format html, use https://htmlformatter.com/
to edit online, use https://gitpod.io/#https://github.com/Yuman/html5
in gitpod, save the changes and run
git commit -am "commit comment"
git push
-->
<html>
<head>
<script>
function process() {
const firstName = document.querySelector('input[name="firstName"]');
const lastName = document.querySelector('input[name="lastName"]');
const dateBirth = document.querySelector('input[name="dateBirth"]');
const genders = document.querySelectorAll('input[name="gender"]');
const address = document.querySelector('input[name="address"]');
const email = document.querySelector('input[name="email"]');
const password = document.querySelector('input[name="password"]');
const phone = document.querySelector('input[name="phone"]');
const courses = document.querySelector('select[name="courses"]');
const comments = document.querySelector('textarea[name="comments"]');
const profile = {};
if (firstName.value == "") {
window.alert("Please enter your first name.");
firstName.focus();
return false;
}
profile.firstName = firstName.value;
if (lastName.value == "") {
window.alert("Please enter your last name.");
lastName.focus();
return false;
}
profile.lastName = lastName.value;
if (dateBirth.value == "") {
window.alert("Please enter your birthday.");
dateBirth.focus();
return false;
}
profile.dateBirth = dateBirth.value;
console.log("genders: " + genders);
let gender = "";
for (let i = 0, len = genders.length; i < len; i++){
if(genders[i].checked){
gender = genders[i].value;
break;
}
}
profile.gender = gender;
let gs = [...genders];
let gselected = gs.find(item => item.checked);
gender = gselected.value;
console.log("gender:" + gender);
if (gender == "") {
window.alert("Please enter your gender.");
gender.focus();
return false;
}
if (address.value == "") {
window.alert("Please enter your address.");
address.focus();
return false;
}
profile.address = address.value;
if (email.value == "") {
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
profile.email = email.value;
if (phone.value == "") {
window.alert("Please enter your telephone number.");
phone.focus();
return false;
}
profile.phone = phone.value;
if (password.value == "") {
window.alert("Please enter your password");
password.focus();
return false;
}
profile.password = password.value;
if (courses.selectedIndex < 0) {
alert("Please enter your course.");
courses.focus();
return false;
}
if (courses.selectedOptions.length >2 ) {
const selectedCourses = courses.selectedOptions;
console.log(selectedCourses);
alert("Select no more than 2.");
courses.focus();
return false;
}
const selectedCourses = courses.selectedOptions;
const selected = [...selectedCourses];
profile.courses = selected.map(o => o.value);
if (comments.length < 10) {
alert("We appreciate your comments");
comments.focus();
return false;
}
profile.comments = comments.value;
localStorage.setItem("profile", JSON.stringify(profile));
window.location.href="reply.html";
return true;
}
function checkName(textInput){
if (textInput.value.length < 2){
alert("Please give your good name.");
textInput.focus();
}
}
</script>
<style>
div {
box-sizing: border-box;
width: 100%;
border: 100px solid black;
float: left;
align-content: center;
align-items: center;
}
form {
margin: 0 auto;
width: 400px;
}
</style>
</head>
<body>
<h1 style="text-align: center"> REGISTRATION FORM </h1>
<form id="regForm"> <!-- "return false;" keeps the input values -->
<p>First Name:
<input type="text" size=65 name="firstName" onchange = "checkName(this);"> </p>
<p>Last Name:
<input type="text" size=65 name="lastName"> </p>
<p>Date of Birth:
<input type="date" size=65 name="dateBirth"> </p>
<p>Please select your gender:</p>
<input type="radio" name="gender" value="male">Male<br>
<input type="radio" name="gender" value="female">Female<br>
<input type="radio" name="gender" value="other">Other<br>
<p> Address:
<input type="text" size=65 name="address"> </p>
<p>E-mail Address:
<input type="email" size=65 name="email"> </p>
<p>Password:
<input type="password" size=65 name="password"> </p>
<p>Telephone:
<input type="text" size=65 name="phone"> </p>
<p>Select Your Courses
<select multiple name="courses">
<option>BTECH</option>
<option>BBA</option>
<option>BCA</option>
<option>B.COM</option>
<option>validate</option>
</select>
</p>
<br>
<p>Comments:
<textarea cols="55" name="comments"> </textarea>
</p>
<p>
<input type="button" value="send" name="Submit" onclick="process()">
</p>
</form>
Another form: <br>
<form onsubmit="alert('Thank you. Good bye.'); return false;">
<p>First Name:
<input type="text" size=65 name="firstName"> </p>
<input type="submit" value="send" name="Submit">
</form>
</body>
</html>