-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.js
74 lines (50 loc) · 1.82 KB
/
payment.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
let checkOut = document.querySelector(".btn");
let digits='12345abcdfgh'
let otp=''
genOtp()
function genOtp() {
otp=''
for (let i = 0; i < 4; i++) {
otp+=digits[Math.floor(Math.random()*10)]
}
console.log(otp)
}
checkOut.addEventListener("click", (e) => {
e.preventDefault()
check = prompt(`Enter Otp. ${otp}`)
if(check==otp){
alert("Thankyou for shopping.")
window.location.href = "index.html";
genOtp()
}else{
alert("Otp incorrect")
genOtp()
}
console.log(check)
})
///////////////////////////////////////////////// saving data in local storage
const storedData = JSON.parse(localStorage.getItem('billingDetailsArray')) || [];
const form = document.querySelector('form');
const proceedToPaymentBtn = document.querySelector('.btn');
proceedToPaymentBtn.addEventListener('click', function(event) {
event.preventDefault();
// Get form data
let name= document.getElementById("name").value
let email= document.getElementById("email").value
let address= document.getElementById("address").value
let city= document.getElementById("city").value
let staus= document.createElement("h3")
// Create an object with the form data
let billingDetails = { name, email, address, city };
storedData.push(billingDetails);
// Save the form data in local storage
localStorage.setItem('billingDetailsArray', JSON.stringify(storedData));
console.log(storedData)
});
// // Get any existing data from local storage
// const storedData = JSON.parse(localStorage.getItem('billingDetailsArray')) || [];
// // Add the new form data to the array
// const billingDetails = { fullName, email, address, city, state, pinCode };
// storedData.push(billingDetails);
// // Save the updated array in local storage
// localStorage.setItem('billingDetailsArray', JSON.stringify(storedData));