-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScript.js
394 lines (349 loc) · 11.4 KB
/
Script.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
function toggledropdown(){
drop = document.getElementById("Dropdown");
if(drop.style.height == "130px")
closedropdown();
else
{
drop.style.height = "130px";
document.getElementById("Droparrow").innerHTML = "▴";
drop.style.border = "solid 1px";
drop.style.borderRadius = "4px";
drop.style.borderColor = "rgb(150, 150, 150)";
}
}
function closedropdown(){
drop = document.getElementById("Dropdown");
drop.style.height = "0px";
document.getElementById("Droparrow").innerHTML = "▾";
drop.style.border = "none";
}
/**********************************************Login**************************************************/
function lvalidusername(){
result = true;
username = document.getElementById("Lusername");
if(username.value.trim() == ""){
username.style.borderColor ="red";
document.getElementById("Lusernameerror").innerHTML = "Pin number/Username cannot be empty";
result = false;
}
else if(username.value.trim().length<6 || username.value.trim().length>15){
username.style.borderColor ="red";
document.getElementById("Lusernameerror").innerHTML = "Invalid Username/Pin";
result = false;
}
else{
username.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Lusernameerror").innerHTML = "";
}
return result;
}
function lvalidpassword() {
var result = true;
password = document.getElementById("Lpassword");
if(password.value == ""){
password.style.borderColor = "red";
document.getElementById("Lpassworderror").innerHTML = "Password cannot be empty";
result = false;
}
else if(password.value.length<8 || password.value.length>20){
password.style.borderColor = "red";
document.getElementById("Lpassworderror").innerHTML = "Invalid Password";
result = false;
}
else{
password.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Lpassworderror").innerHTML = "";
}
return result;
}
function lusernamedefault(username){
username.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Lusernameerror").innerHTML = "";
document.getElementById("Lusernameexisterror").innerHTML = "";
}
function lpassworddefault(password){
password.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Lpassworderror").innerHTML = "";
}
function validloginform(){
username = document.getElementById("Lusername");
password = document.getElementById("Luassword");
var user = lvalidusername(username);
var pass = lvalidpassword(password);
if(user && pass)
return true;
else
return false;
}
/*function lvalidpasswordabove(){
username = document.getElementById("Lusername");
lvalidusername(username);
}*/
/**********************************************Signup**************************************************/
function validsignupform(){
var user = svalidusername();
var name = svalidname();
var password = svalidpassword();
var cpasword = svalidcpassword();
var email = svalidemail();
var mobile = svalidmobile();
if(user && name && password && cpasword && email && mobile)
return true;
else
return false;
}
function changetopin(){
document.getElementById("Spin").innerHTML = "Pin number";
}
function changetousername(){
document.getElementById("Spin").innerHTML = "Username";
}
function svalidusername(){
var result = true;
var username = document.getElementById("Susername");
if(username.value.trim() == ""){
var string = document.getElementById("Spin").innerHTML;
username.style.borderColor = "red";
document.getElementById("Susernameerror").innerHTML = string + " cannot be empty";
result = false;
}
else if(document.getElementById("Studentradioselected").checked && (username.value.trim().length != 10)){
document.getElementById("Susernameerror").innerHTML = "Pin number must be 10 characters long";
username.style.borderColor = "red";
result = false;
}
else if(document.getElementById("Facultyradioselected").checked && (username.value.trim().length<6 || username.value.trim().length>15)){
document.getElementById("Susernameerror").innerHTML = "Username must be 6 to 15 characters long";
username.style.borderColor = "red";
result = false;
}
/*else{
username.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Susernameexisterror").innerHTML = "";
}*/
return result;
}
function susernamedefault(username){
username.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Susernameerror").innerHTML = "";
}
function snamedefault(name){
name.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Snameerror").innerHTML = "";
}
function spassworddefault(password){
password.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Spassworderror").innerHTML = "";
}
function scpassworddefault(cpassword){
cpassword.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Scpassworderror").innerHTML = "";
}
function semaildefault(email){
email.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Semailerror").innerHTML = "";
}
function smobiledefault(mobile){
mobile.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Smobileerror").innerHTML = "";
}
function svalidname(){
var result = true;
var name = document.getElementById("Sname");
if(name.value.trim() == ""){
name.style.borderColor = "red";
document.getElementById("Snameerror").innerHTML = "Name cannot be empty";
result = false;
}
else{
name.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Snameerror").innerHTML = "";
}
return result;
}
function svalidpassword(){
var password = document.getElementById("Spassword");
if(password.value == ""){
password.style.borderColor = "red";
document.getElementById("Spassworderror").innerHTML = "Password cannot be empty";
return false;
}
else if(password.value.length < 8 || password.value.length > 20){
password.style.borderColor = "red";
document.getElementById("Spassworderror").innerHTML = "Password must be 8 to 20 characters long";
return false;
}
else{
password.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Spassworderror").innerHTML = "";
}
return true;
}
function svalidcpassword(){
var password = document.getElementById("Spassword");
var cpassword = document.getElementById("Scpassword");
if(password.value != cpassword.value){
cpassword.style.borderColor = "red";
document.getElementById("Scpassworderror").innerHTML = "Password does not match";
return false;
}
else{
cpassword.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Scpassworderror").innerHTML = "";
}
return true;
}
function svalidemail(){
var result = true;
var email = document.getElementById("Semail");
if(email.value.trim() == ""){
email.style.borderColor = "red";
document.getElementById("Semailerror").innerHTML = "Email cannot be empty";
result = false;
}
else if(!email.value.includes('@') ||
!email.value.includes('.', email.value.indexOf('@')+2) ||
email.value.length - email.value.indexOf('@') < 5 ||
email.value.lastIndexOf('.') == email.value.length-1){
email.style.borderColor = "red";
document.getElementById("Semailerror").innerHTML = "Invalid email";
result = false;
}
else{
email.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Semailerror").innerHTML = "";
}
return result;
}
function svalidmobile(){
var result = true;
var mobile = document.getElementById("Smobile");
if(mobile.value.trim() == ""){
mobile.style.borderColor = "red";
document.getElementById("Smobileerror").innerHTML = "Mobile cannot be empty";
result = false;
}
else if(mobile.value.trim().length != 10){
mobile.style.borderColor = "red";
document.getElementById("Smobileerror").innerHTML = "Invalid mobile number";
result = false;
}
else{
mobile.style.borderColor = "rgb(150, 150, 150)";
document.getElementById("Smobileerror").innerHTML = "";
}
for (var i = mobile.value.trim().length - 1; i >= 0; i--) {
var c = mobile.value.charCodeAt(i);
if(c <48 || c > 57){
result = false;
break;
}
}
return result;
}
/*********************************Questions**************************************/
function validpoll(){
if(!document.getElementById("Yesradio").checked && !document.getElementById("Noradio").checked){
document.getElementById("Pollerror").innerHTML = "You must choose one of the above option";
return false;
}
document.getElementById("Pollerror").innerHTML = "";
return true;
}
function susernameexists(msg){
var username = document.getElementById("Susername");
username.style.borderColor = "red";
document.getElementById("Susernameerror").innerHTML = msg;
}
function hideiframe(){
document.getElementById("iframe").setAttribute("src", "about:blank");
document.getElementById("iframebackground").style.display = 'none';
}
function showiframe(button){
document.getElementById("iframebackground").style.display = 'block';
}
function showcreatepolliframe(){
}
function createoptions(number){
number = number.value;
if(number>10 || number<2){
document.getElementById("inputerror").innerHTML="Options must be 2 to 10";
}
else
{
document.getElementById("inputerror").innerHTML="";
var inputs = document.getElementById("inputoptions");
while(inputs.firstChild)
inputs.removeChild(inputs.firstChild);
for (var i = 2; i < number ; i++)
{
var input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("class", "Optioninput");
input.setAttribute("placeholder", "Option " + `${i+1}`);
input.setAttribute("name", "option"+`${i+1}`);
input.setAttribute("oninput", "inputdefault(this)");
inputs.appendChild(input);
span = document.createElement("span");
span.setAttribute("class", "errors");
span.setAttribute("id", "Optionerror"+`${i+1}`);
inputs.appendChild(span);
inputs.appendChild(document.createElement("br"));
}
}
}
function validquestion(){
var question = document.getElementById("Questioninput");
if(question.value == ""){
var question = document.getElementById("Questionerror").innerHTML = "Question cannot be empty";
return false;
}
return true;
}
function validinput(){
var input = document.getElementById("inputnumber");
if(input>10 || input<2){
return false;
}
return true;
}
function validinputs(){
var inputs = document.getElementsByClassName("Optioninput");
var inputnumber = document.getElementById("inputnumber").value;
var result = true;
for(var i=0;i<inputnumber;i++){
if(inputs[i].value==""){
inputs[i].nextElementSibling.innerHTML="Option cannot be empty";
result=false;
}
}
return result;
}
function inputdefault(input){
input.nextElementSibling.innerHTML="";
}
function validcreatepoll(){
var question = validquestion();
var input = validinput();
var inputs = validinputs();
if(question && input && inputs){
showcreatepolliframe();
return true;
}
else
return false;
}
function validanswer(){
var radios = document.getElementsByClassName("radio");
var l = radios.length;
for (var i=0;i<l;i++) {
if (radios[i].checked) {
return true;
}
}
document.getElementById("Pollsubmiterror").innerHTML = "You must select an option";
return false;
}
function clearpollsubmiterror(){
document.getElementById("Pollsubmiterror").innerHTML = "";
}