-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard-payment.js
88 lines (75 loc) · 2.9 KB
/
card-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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const cardName = document.querySelector("#full-name");
const cardNumber = document.querySelector("#card-number");
const cardMonth = document.querySelector("#month");
const cardYear = document.querySelector("#year");
const cardCVC = document.querySelector("#CVC");
const confirmButton = document.querySelector("#confirm-button");
const errorMessage = document.querySelector("#error-border");
const showError = document.querySelector("#error");
const inputs = document.querySelectorAll("input");
const form = document.querySelector("#form");
// if someone fucks up the form, show these error features
function showErrorBorder(submitCardInfo) {
if (cardMonth.value === "" || cardMonth.value == null) {
// turns border red
cardMonth.classList.add("error-border");
// displays error message
showError.style.visibility = "visible";
}
if (cardYear.value === "" || cardYear.value == null) {
// turns border red
cardYear.classList.add("error-border");
// displays error message
showError.style.visibility = "visible";
}
if (cardCVC.value === "" || cardCVC.value == null) {
// turns border red
cardCVC.classList.add("error-border");
// displays error message
showError.style.visibility = "visible";
}
// when clicking submit with errors, doesn't refresh page, displays errors
submitCardInfo.preventDefault();
}
confirmButton.addEventListener("click", showErrorBorder);
// everything above is correct; do not change!!! //
// allows card info input to replace example card info shown on card images //
const exampleCardNumber = document.querySelector("#example-number");
const exampleCardName = document.querySelector("#example-name");
const exampleCardMonth = document.querySelector("#example-month");
const exampleCardCVC = document.querySelector("#example-cvc");
const exampleCardYear = document.querySelector("#example-year");
cardName.oninput = () => {
exampleCardName.innerText = cardName.value;
cardName.classList.remove("error");
};
cardNumber.oninput = () => {
exampleCardNumber.innerText = cardNumber.value;
cardNumber.classList.remove("error");
// exampleCardNumber.innerText.push(" ")
// space numbers out every 4 numbers
};
function limit(element, maxChars) {
if (element.value.length > maxChars) {
element.value = element.value.substr(0, maxChars);
}
}
cardMonth.oninput = () => {
exampleCardMonth.innerText = cardMonth.value;
cardMonth.classList.remove("error");
};
cardYear.oninput = () => {
exampleCardYear.innerText = cardYear.value;
cardYear.classList.remove("error");
};
cardCVC.oninput = () => {
exampleCardCVC.innerText = cardCVC.value;
cardCVC.classList.remove("error");
};
//IF ALL CONDITIONS ARE MET //
// if (inputs.innerText =
confirmButton.addEventListener("click", function (e) {
const confirmationMessage = document.querySelector("#confirmation-message");
form.style.display = "none";
confirmationMessage.style.display = "flex";
});