-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (22 loc) · 922 Bytes
/
script.js
File metadata and controls
24 lines (22 loc) · 922 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
const wrapper = document.querySelector(".wrapper"),
qrInput = document.querySelector(".form input"),
generateBtn = wrapper.querySelector(".form button"),
qrImg = wrapper.querySelector(".qr-code img");
generateBtn.addEventListener("click", () => {
let qrValue = qrInput.value;
if (!qrValue) return; // if the input is empty then return from here
generateBtn.innerText = "Generating QR Code...";
// getting a QR code of user entered value using the qrserver
// api and passing the api returned img src to qrImg
qrImg.src = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${qrValue}`;
qrImg.addEventListener("load", () => {
// once QR code img loaded
wrapper.classList.add("active");
generateBtn.innerText = "Generate QR Code";
});
});
qrInput.addEventListener("keyup", () => {
if (!qrInput.value) {
wrapper.classList.remove("active");
}
});