-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
111 lines (101 loc) · 3.32 KB
/
app.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
var i = 1;
var counter = 0;
var cart = [];
var totalCart = 0;
function item(name, price, count) {
this.name = name;
this.price = price;
this.count = count;
}
let el = document.getElementsByClassName("add-to-cart");
var btnsNum = el.length;
for (i = 0; i < btnsNum; i++) {
var button = el[i];
button.addEventListener("click", function add(event) {
var buttonclicked = event.target;
var itemName = buttonclicked.getAttribute("data-name");
var itemPrice = Number(buttonclicked.getAttribute("data-price"));
var itemCount = 1;
totalCart += itemPrice;
var Item = new item(itemName, itemPrice, itemCount);
cart.push(Item);
console.log(Item);
console.log(cart);
var nweRow = document
.querySelector(".receipt")
.appendChild(document.createElement("tr"));
nweRow.className = "tt";
document
.querySelector(".receipt")
.appendChild(
document.createElement("td")
).textContent = buttonclicked.getAttribute("data-name");
document
.querySelector(".receipt")
.appendChild(
document.createElement("td")
).textContent = buttonclicked.getAttribute("data-price");
counter++;
document.querySelector(".cartCount").innerHTML = counter;
document.querySelector(".total-cart").innerHTML = totalCart;
});
}
let or = document.querySelector(".orderNow");
or.addEventListener("click", function () {
for (i = 0; i < counter; i++) {
document.querySelector(".show-cart").deleteTFoot();
}
cart = [];
counter = 0;
totalCart = 0;
var nweRow = document
.querySelector(".show-cart")
.appendChild(document.createElement("tfoot"));
nweRow.className = "receipt";
document.querySelector(".cartCount").innerHTML = counter;
document.querySelector(".total-cart").innerHTML = totalCart;
})
function plusItem() {
++i;
document.getElementById("itemNum").innerHTML = i;
}
function minusItem() {
if (i > 1) {
--i;
document.getElementById("itemNum").innerHTML = i;
}
}
function countChars(obj) {
var maxLength = 500;
var strLength = obj.value.length;
document.getElementById("charNum").innerHTML = strLength + ' / ' + maxLength;
}
function emptyReview() {
document.getElementById('Review').addEventListener("keydown", function () {
document.getElementById('message').style.display = 'none';
});
if (document.getElementById('Review').value == '') {
document.getElementById('message').style.display = 'block';
document.getElementById('message').innerHTML = 'Please type your review';
document.getElementById('message').style.color = '#a80e0e';
return false;
} else
return true;
}
function checkName() {
if (document.getElementById('personName').value == '') {
document.getElementById('personName').value = 'Customer';
return false;
} else
return true;
}
function submitReview() {
if (checkName() == true && emptyReview() == true) {
document.getElementById("frm1").submit();
}
}
function slidIN() {
document.getElementById('addReview').style.height = 'max-content';
document.getElementById('addReview').style.opacity = '100%';
document.getElementById('addReview').style.marginLeft = '0rem';
}