-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (24 loc) · 1.06 KB
/
script.js
File metadata and controls
35 lines (24 loc) · 1.06 KB
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
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;
//if no input then no generation
generateBtn.innerText = "Generating QR Code...";
//if the input is empty then return from here
//getting qr code of user entered value using the qrserver
//api and passing the api returned img src to qrImg in img section
qrImg.src = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${qrValue}`;
qrImg.addEventListener("load", () => {
wrapper.classList.add("active");
generateBtn.innerText = "Generate QR Code";
});
});
qrInput.addEventListener("keyup", () => {
if (!qrInput.value) {
wrapper.classList.remove("active");
//if after generation shome one while remove the input from in put then qr while be also erase
}
});