-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
33 lines (28 loc) · 977 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
24
25
26
27
28
29
30
31
32
33
// JavaScript Code
const generateButton = document.getElementById("generate-button");
const downloadButton = document.getElementById("download-button");
const inputField = document.getElementById("text-input");
const inputWarning = document.getElementById("input-warning");
const qrCode = new QRCode(document.getElementById("qr-code"), {
width: 300,
height: 300,
});
generateButton.addEventListener("click", () => {
const textInput = inputField.value;
if (textInput.length < 15) {
// Minimum length validation
inputWarning.textContent = "Invalid input"; // Display warning
return;
} else {
inputWarning.textContent = ""; // Clear any previous warning
}
qrCode.clear();
qrCode.makeCode(textInput);
downloadButton.style.display = "block";
});
downloadButton.addEventListener("click", () => {
const qrCodeDataUrl = document
.getElementById("qr-code")
.getElementsByTagName("img")[0].src;
downloadButton.href = qrCodeDataUrl;
});