-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (31 loc) · 985 Bytes
/
index.js
File metadata and controls
35 lines (31 loc) · 985 Bytes
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
import checkCardNumber from "./checkCardNumber.js";
const form = document.querySelector("form");
const input = form.querySelector("input");
const closeBtn = document.querySelector(".effect .closeBtn");
const resultBox = document.querySelector(".effect");
const result = document.querySelector("p.text");
const showText = (e) => {
e.preventDefault();
let text = "";
if (input.value) {
text = checkCardNumber(
Number(input.value.split(" ").join("").split("-").join(""))
);
result.textContent = text;
input.focus();
} else {
result.textContent = `You should enter something,
if you want a verification...`;
}
resultBox.classList.add("active");
form.classList.add("active");
};
const hideText = (e) => {
e.preventDefault();
result.textContent = "";
input.value = "";
resultBox.classList.remove("active");
form.classList.remove("active");
};
form.addEventListener("submit", showText);
closeBtn.addEventListener("click", hideText);