Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
```javascript
function generateQR() {
const inputElement = document.getElementById("text");
const qrCodeDiv = document.getElementById("qrcode");
// Get HTML elements
const inputElement = document.getElementById("text");
const qrCodeDiv = document.getElementById("qrcode");
const generateButton = document.getElementById("generateButton");

if (inputElement.value.trim() === "") {
// Validate input and generate QR code on button click
generateButton.addEventListener("click", () => {
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");
alert("Input must be a string");
return;
}
}

document.getElementById("generateButton").addEventListener("click", () => generateQR());
const qrCode = new QRCode(qrCodeDiv, {
text: inputElement.value,
width: 200,
height: 200
});
});
```