-
Notifications
You must be signed in to change notification settings - Fork 0
/
login-page.html
110 lines (89 loc) · 2.87 KB
/
login-page.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
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url('img/login2.jpg');
background-repeat: no-repeat;
background-position-x: center;
background-attachment: fixed;
background-size: 100% 100%;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Js form Validation</title>
<link rel="stylesheet" href="css/login-page.css">
</head>
<body>
<div class="background-image"></div>
<center>
<h1>Welcome to HOARD WARRIORS</h1>
<form action="/myaction.php" name="myform" onsubmit="return validateForm()" method="post">
<div class="formdesign" id="name">
Name: <input type="text"name="fname" required><span class="fromerror"><b></b></span>
</div>
<div class="formdesign" id="email">
Email: <input type="email"name="femail" required><span class="fromerror"><b></b></span>
</div>
<div class="formdesign" id="phone"required>
Phone: <input type="phone"name="fphone"required><span class="fromerror"><b></b></span>
<div class="formdesign" id="pass"required>
Password: <input type="password"name="fpass"required><span class="fromerror"><b></b></span>
</div>
<div class="formdesign" id="cpass">
Confirm Password: <input type="text"name="fcpass"required>
<span class="fromerror"><b></b></span>
</div>
<input type="Submit" class="but" value="submit">
</form>
</center>
</body>
<script>
function clearErrors(){
errors=document.getElementsByClassName('fromerror');
for(let item of errors)
{
item.innerHTML="";
}
}
function seterror(id,error){
//sets error inside tag of id
element=document.getElementById(id);
element.getElementsByClassName('fromerror')[0].innerHTML=error;
}
function validateForm(){
var returnval=true;
clearErrors();
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","Enter your name");
returnval=false;
}
var email=document.forms['myform']["femail"].value;
if(email.length<5){
seterror("email","enter valid email");
returnval=false;
}
var phone=document.forms['myform']["fphone"].value;
if(phone.length!=10){
seterror("phone","enter valid phone number");
returnval=false;
}
var pass=document.forms['myform']["fpass"].value;
if(pass.length<6){
seterror("pass","Password must be atleast 6 charecters");
returnval=false;
}
var cpass=document.forms['myform']["fcpass"].value;
if(cpass!=pass){
seterror("cpass","Password and confirm password should be matched");
returnval=false;
}
return returnval;
}
</script>
</html>