-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
23 lines (21 loc) · 889 Bytes
/
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
const wrapper = document.querySelector(".wrapper"),
qrInput = wrapper.querySelector(".form input"),
generateBtn = wrapper.querySelector(".form button"),
qrImg = wrapper.querySelector(".qr-code img");
generateBtn.addEventListener("click", () => {
let qrValue = qrInput.value;
if(!qrValue) return;
generateBtn.innerText = "Generating QR Code..."; // if the input is empty then return from here
// 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=170x170&data=${qrValue}`;
qrImg.addEventListener("load", () => {
wrapper.classList.add("active");
generateBtn.innerText = "Generate QR Code";
});
});
qrInput.addEventListener("keyup", () => {
if(!qrInput.value) {
wrapper.classList.remove("active");
}
})