forked from Rohit27698/carver_Clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
otp.html
70 lines (64 loc) · 2.22 KB
/
otp.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="//images-static.nykaa.com/media/favicon/default/nykaa_favicon_a.png" type="image/x-icon">
<title>enter otp</title>
<link rel="stylesheet" href="OTP.css" />
<link rel="stylesheet" href="home.html"/>
</head>
<body>
<div class="container"><br>
<h2>OTP Verification</h2><br>
<form>
<div class="form-group">
<label for="otp"> Welcome back <b>Carver user,</b> <br> Please enter the OTP sent on <br> your phone <br>
(Be sure to check your spam folder)</label>
<input type="tel" id="otp" name="otp" required disabled />
</div>
<div class="form-group">
<button type="button" id="send-otp">Send OTP</button>
</div>
<div class="form-group">
<button type="submit" id="submit-otp" disabled>Submit OTP</button><br><br>
<img src="https://th.bing.com/th/id/OIP.FukKltxmyZLI-m8nDYVQ4gHaHa?pid=ImgDet&w=512&h=512&rs=1" alt="">
</div>
</form>
</div>
</body>
</html>
<script>const otpInput = document.getElementById("otp");
const sendOtpButton = document.getElementById("send-otp");
const submitOtpButton = document.getElementById("submit-otp");
// Function to generate random 6-digit OTP
function generateOTP() {
const digits = "0123456789";
let OTP = "";
for (let i = 0; i < 4; i++) {
OTP += digits[Math.floor(Math.random() * 10)];
}
return OTP;
}
sendOtpButton.addEventListener("click", () => {
// Generate and display OTP
const OTP = generateOTP();
alert(`Your OTP is ${OTP}`);
otpInput.value = OTP;
// Enable OTP input and submit button
otpInput.disabled = false;
submitOtpButton.disabled = false;
});
submitOtpButton.addEventListener("click", (e) => {
e.preventDefault();
const otp = otpInput.value.trim();
// Check if OTP is valid
if (/^\d{4}$/.test(otp)) {
alert("OTP verified successfully!");
window.location.href = "success.html"
// Do something else on successful verification
} else {
alert("Wrong OTP!")
}
});
</script>