-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
52 lines (41 loc) · 1.37 KB
/
script.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
const netPrice = document.querySelector("#net-price");
const vatRate = document.querySelector("#vat-rate");
const vatAdded = document.querySelector("#vat-added")
const incAmount = document.querySelector("#inc-amount");
const calcBtn = document.querySelector("#calc-btn")
const resetBtn = document.querySelector("#reset-btn")
function VATInclusiveAmount(price, rate) {
let vatAddedPrice = Number((price * (rate / 100)));
vatAdded.value = vatAddedPrice.toFixed(2);
let totalAmount = Number(price) + vatAddedPrice;
return totalAmount;
}
calcBtn.addEventListener('click', function() {
if (netPrice.value === "" || isNaN(netPrice.value)) {
// show red border
netPrice.style.border = "1px solid red";
// removing red border after 1.5s
setTimeout(function() {
netPrice.style.border = "1px solid transparent";
}, 1500);
netPrice.value = "";
}
if (vatRate.value === "" || isNaN(vatRate.value)) {
// show red border
vatRate.style.border = "1px solid red";
// removing red border after 1.5s
setTimeout(function() {
vatRate.style.border = "1px solid transparent";
}, 1500);
// remove wrong value
vatRate.value = "";
}
let finalAmount = VATInclusiveAmount((netPrice.value), (vatRate.value));
incAmount.value = finalAmount;
})
resetBtn.addEventListener("click", function() {
netPrice.value = "";
vatRate.value = "";
vatAdded.value = "";
incAmount.value = "";
})