-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (24 loc) · 745 Bytes
/
Copy pathscript.js
File metadata and controls
28 lines (24 loc) · 745 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
```javascript
function generateQR() {
const inputElement = document.getElementById("text");
const qrCodeDiv = document.getElementById("qrcode");
if (inputElement.value.trim() === "") {
alert("Please enter text or URL");
return;
}
if (typeof inputElement.value !== "string") {
throw new Error("Input must be a string");
}
try {
const qrcode = new QRCode(qrCodeDiv, {
text: inputElement.value,
width: 200,
height: 200
});
} catch (error) {
console.error(error);
alert("An error occurred while generating the QR code");
}
}
document.getElementById("generateButton").addEventListener("click", () => generateQR());
```