Skip to content

Commit 7129082

Browse files
committed
Just added password reset-with javascript on my repo.
1 parent b03102c commit 7129082

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

form.html

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width", width="device-width">
6+
<title>Project Document</title>
7+
<style>
8+
.err{
9+
color: red;
10+
11+
}
12+
input{
13+
padding: 10px 40px;
14+
margin: 15px 0px;
15+
border-radius: 20px;
16+
background-color: white;
17+
}
18+
button{
19+
padding: 20px 50px;
20+
margin: 15px 0;
21+
border-radius: 20px;
22+
border: none;
23+
color: white;
24+
box-shadow: 1px 2px 2px;
25+
background-color: orange;
26+
27+
}
28+
form{
29+
padding: 50px;
30+
margin: 20px 10px;
31+
align-items: center;
32+
}
33+
body{
34+
background-color: rgb(26, 26, 26);
35+
color: white;
36+
font-size: 19px;
37+
font-family: sans-serif;
38+
}
39+
.main_container{
40+
background-color: rgb(48, 48, 48);
41+
padding: 50px;
42+
border-radius: 60px 60px;
43+
align-items: center;
44+
}
45+
.main_container{
46+
box-shadow: 2px 2px 4px 2px rgb(134, 134, 134);
47+
}
48+
</style>
49+
</head>
50+
<body>
51+
<form id="password_resetform">
52+
<center>
53+
<diV style="border: 1px solid black; height: 440px;width: 70%;" class="main_container">
54+
<h1>PASSWORD RESET WITH JAVASCRIPT</h1>
55+
<p>
56+
<label for="oldpassword">old password</label>
57+
<input type="password" id="oldpassword" name="oldpassword">
58+
<br>
59+
<span class="err" data-err="oldpasswordErr"></span>
60+
</p>
61+
<p>
62+
<label for="newpassword">new password</label>
63+
<input type="password" id="newpassword" name="newpassword">
64+
<br>
65+
<span class="err" data-err="newpasswordErr"></span>
66+
</p>
67+
<p>
68+
<label for="confirmpassword">confirm password</label>
69+
<input type="password" id="confirmpassword" name="confirmpassword">
70+
<br>
71+
<span class="err" data-err="confirmpasswordErr"></span>
72+
</p>
73+
<button>reset</button>
74+
</center>
75+
</form>
76+
<script src="form.js"></script>
77+
</body>
78+
</html>

form.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
let resetForm = document.forms.password_resetform
2+
let userInput = document.querySelectorAll("input");
3+
resetForm.onsubmit= (e)=> {
4+
e.preventDefault();
5+
console.log(e.target)
6+
7+
let formErr ={
8+
oldpasswordErr: "",
9+
newpasswordErr: "",
10+
confirmpasswordErr: "",
11+
12+
}
13+
let oldpassword= resetForm.oldpassword.value.trim();
14+
let newpassword= resetForm.newpassword.value.trim();
15+
let confirmpassword= resetForm.confirmpassword.value.trim();
16+
17+
if(oldpassword == ""){
18+
formErr.oldpasswordErr = "please fill in the blank ";
19+
20+
}else if(newpassword == ""){
21+
formErr.newpasswordErr= "please fill in the blank";
22+
23+
}else if(newpassword == oldpassword){
24+
formErr.newpasswordErr= "must be a valid password that you've not used in the past";
25+
26+
}else if(confirmpassword == ""){
27+
formErr.confirmpasswordErr = "please fill in the blank";
28+
29+
}else if(confirmpassword != newpassword){
30+
formErr.confirmpasswordErr = "must be the same value with your new password";
31+
32+
}else{
33+
console.log({oldpassword,newpassword,confirmpassword});
34+
alert("congratulation you've successfully reset your password,your new password is "+newpassword);
35+
36+
}
37+
let errElement = document.querySelectorAll(".err");
38+
console.log(errElement)
39+
for(let i=0; i < errElement.length; i++){
40+
let errElements = errElement[i];
41+
42+
console.log(formErr);
43+
errElements.innerHTML = formErr[""+errElements.dataset.err+""]
44+
45+
}
46+
47+
48+
49+
}

0 commit comments

Comments
 (0)