-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout.js
139 lines (128 loc) · 4.49 KB
/
checkout.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
let logo = document.getElementById(`nav-logo-img`);
logo.src = `https://i.ibb.co/sqp9KQk/foodium-logo.png`;
logo.onclick = () => {
window.location.replace(`index.html`);
};
let project_name = document.getElementById(`project-name`);
project_name.onclick = () => {
window.location.replace(`index.html`);
};
//some required accesses
let cart_count = document.getElementById(`cart-count`);
let cart_amount = document.getElementById(`cart-amount`);
let billData = document.querySelector(".clicked-items");
//let selectedItemsArr =
//JSON.parse(localStorage.getItem("selectedItemsArr")) || [];
let selectedItemsArr =
JSON.parse(localStorage.getItem(`selectedItemsArr`)) || [];
//dropdown of navbar
let help_btn = document.getElementById(`nav-dropdown`);
help_btn.onclick = () => {
document.getElementById("myDropdown").classList.toggle("show");
};
// Close the dropdown menu if the user clicks outside of it
window.onclick = function (event) {
if (!event.target.matches(".dropbtn")) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains("show")) {
openDropdown.classList.remove("show");
}
}
}
};
//EO: dropdown of navbar
// On form submit,
let form = document.getElementById(`checkout-form`);
form.onsubmit = (e) => {
e.preventDefault();
window.location.replace(`transition.html`);
//fname, address, adr, city, state, zip, cname, ccnum, expmonth, expyear, cvv
/* let fname_div = document.getElementById(`fname`).value;
let address_div = document.getElementById(`address`).value;
let address_div2 = document.getElementById(`adr`).value;
let city_div = document.getElementById(`city`).value;
let state_div = document.getElementById(`state`).value;
let zip_div = document.getElementById(`zip`).value;
let cname_div = document.getElementById(`cname`).value;
let ccnum_div = document.getElementById(`ccnum`).value;
let expmonth_div = document.getElementById(`expmonth`).value;
let expyear_div = document.getElementById(`expyear`).value;
let cvv_div = document.getElementById(`cvv`).value;
console.log(
fname_div,
address_div,
address_div2,
city_div,
state_div,
zip_div,
cname_div,
ccnum_div,
expmonth_div,
expyear_div,
cvv_div
);*/
};
//onclick of promo code btn,
let pcbtn = document.getElementById(`promo-code-btn`);
pcbtn.onclick = () => {
appendCode(pcbtn);
};
//onclick of gift card btn,
let gcbtn = document.getElementById(`gift-card-btn`);
gcbtn.onclick = () => {
appendCode(gcbtn);
};
//function creating input for promo code or gift card
const appendCode = (ele) => {
let gc_div = document.getElementById(`gift-card-div`);
if (ele.id == `promo-code-btn`) {
let temp_div = document.createElement(`div`);
let ipbox = document.createElement(`input`);
ipbox.placeholder = `Add Promo Code here`;
let cclbtn = document.createElement(`button`);
cclbtn.innerText = `cancel`;
cclbtn.setAttribute(`id`, `promo-code-btn`);
cclbtn.onclick = () => {
temp_div.innerHTML = null;
};
temp_div.append(ipbox, cclbtn);
gc_div.append(temp_div);
} else if (ele.id == `gift-card-btn`) {
let temp_div = document.createElement(`div`);
let ipbox = document.createElement(`input`);
ipbox.placeholder = `Redeem Gift Card here`;
let cclbtn = document.createElement(`button`);
cclbtn.innerText = `cancel`;
cclbtn.setAttribute(`id`, `promo-code-btn`);
cclbtn.onclick = () => {
temp_div.innerHTML = null;
};
temp_div.append(ipbox, cclbtn);
gc_div.append(temp_div);
}
};
// function appending all cart items in cart section
appendBill = (selectedItemsArr) => {
billData.innerHTML = null;
selectedItemsArr.forEach(function (el) {
let div = document.createElement("div");
div.className = "one_item_bill";
let bill_image_container = document.createElement("div");
bill_image_container.className = "bill_image_container";
let img = document.createElement("img");
img.src = el.image;
img.className = "selectedImage";
bill_image_container.append(img);
let sub_container = document.createElement("div");
sub_container.className = "sub_container";
sub_container.innerText = el.name;
div.append(bill_image_container, sub_container);
billData.append(div);
});
};
appendBill(selectedItemsArr);
cart_count.innerText = selectedItemsArr.length;
cart_amount.innerText = "$" + selectedItemsArr.length * 12;