-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.js
105 lines (82 loc) · 2.46 KB
/
registration.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
//8 button: user can select the course by button in registation page.
var selectedSkills = [];
function toggleSkill(skill) {
var index = selectedSkills.indexOf(skill);
if (index === -1) {
selectedSkills.push(skill);
} else {
selectedSkills.splice(index, 1);
}
document.getElementById("resultInput").value = selectedSkills.join(", ");
}
// function previewImage() {
var input = document.getElementById("img");
var preview = document.getElementById("preview-img");
var file = input.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function (e) {
preview.src = e.target.result;
};
reader.readAsDataURL(file);
}
//adding browser photo in registration form.
function previewImage() {
var input = document.getElementById("img");
var preview = document.getElementById("preview-img");
var file = input.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function (e) {
preview.src = e.target.result;
};
reader.readAsDataURL(file);
}
}
//registration form error
function clearErrors() {
errors = document.getElementsByClassName("formerror");
for (let item of errors) {
item.innerHTML = "";
}
}
function seterror(id, error) {
//sets error inside tag of id
element = document.getElementById(id);
element.getElementsByClassName("formerror")[0].innerHTML = error;
}
function validateForm() {
var returnval = true;
clearErrors();
//perform validation and if validation fails, set the value of returnval to false
var name = document.forms["myForm"]["fname"].value;
if (name.length < 5) {
seterror("name", "*Length of name is too short");
returnval = false;
}
if (name.length == 0) {
seterror("name", "*Length of name cannot be zero!");
returnval = false;
}
var course = document.forms["myForm"]["fcourse"].value;
if (course.length <= 5) {
seterror("course", "*Please enter your course!");
returnval = false;
}
var jobtype = document.forms["myForm"]["fjobtype"].value;
if (jobtype.length <= 5) {
seterror("jobtype", "*Enter your full job title name!");
returnval = false;
}
var location = document.forms["myForm"]["flocation"].value;
if (location.length < 3) {
seterror("location", "*Enter your city name!");
returnval = false;
}
var social = document.forms["myForm"]["fsocial"].value;
if (social == 0) {
seterror("social", "*Length of social cannot be zero! ");
returnval = false;
}
return returnval;
}