forked from Git21221/IBMSkillsBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathver.js
51 lines (44 loc) · 1.32 KB
/
ver.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
const otp = document.querySelectorAll('.otp_field');
otp[0].focus();
otp.forEach((field, index) =>{
field.addEventListener('keydown', (e) =>{
if(e.key >=0 && e.key<=9){
otp[index].value = "";
setTimeout(() => {
otp[index+1].focus();
},4);
}
else if(e.key === 'Backspace'){
setTimeout(() => {
otp[index-1].focus();
},4);
}
});
});
const form = document.querySelector('.form form'),
submitbtn = form.querySelector('.submit .button'),
errortxt = form.querySelector('.error-text');
form.onsubmit = (e) => {
e.preventDefault();
}
submitbtn.onclick = () =>{
let xhr = new XMLHttpRequest();
xhr.open("POST","./UI/reotp.php",true);
xhr.onload = () => {
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status == 200){
let data = xhr.response;
if(data=="OK"){
alert("Password Changed Succesfully");
location.href="./UI/Login.html";
}
else{
errortxt.textContent = data;
errortxt.style.display = "block";
}
}
}
}
let formData = new FormData(form);
xhr.send(formData);
}