Skip to content

Commit afd42b7

Browse files
Merge pull request #858 from Manjusri-A/patch-29
Update script.js
2 parents 888e56f + 51d6d56 commit afd42b7

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

QR-CODE-Generator/script.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const btn = document.querySelector('.btn');
2-
const code = document.querySelector('.code');
3-
const input = document.querySelector('.input');
4-
const toast = document.querySelector('#toast');
1+
function generateQRCode() {
2+
const inputText = document.getElementById('input-text').value;
3+
const qrCodeImage = document.getElementById('qrcode');
4+
const toast = document.getElementById('toast');
55

6-
btn.addEventListener('click', generate);
6+
if (inputText.trim() === "") {
7+
alert("Please enter some text to generate a QR code.");
8+
return;
9+
}
710

8-
function generate() {
9-
const data = input.value;
10-
const URL = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${data}`;
11-
code.src = URL;
11+
12+
const qrCodeUrl = https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(inputText)}&size=200x200;
13+
qrCodeImage.src = qrCodeUrl;
14+
qrCodeImage.style.display = 'block';
1215

13-
toastDiv();
14-
}
15-
16-
function toastDiv() {
17-
toast.className = "show";
18-
setTimeout(function() {
19-
toast.className = toast.className.replace("show", "");
20-
}, 2000)
16+
17+
toast.style.display = 'block';
18+
setTimeout(() => {
19+
toast.style.display = 'none';
20+
}, 3000);
2121
}

0 commit comments

Comments
 (0)