-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (37 loc) · 1.24 KB
/
script.js
File metadata and controls
40 lines (37 loc) · 1.24 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
36
37
38
39
40
var input = document.getElementById("input");
var btn = document.getElementById("btn");
var qrCode = document.getElementById("qr-code");
const url = "https://api.qrserver.com/v1/create-qr-code/?size=170x170&data=";
// Add event listener to button
btn.addEventListener("click", ()=>{
var inputValue = input.value.replace(/\s+/g, ""); // Remove all spaces
if(!inputValue){
qrCode.innerHTML = "";
qrCode.classList.remove("active");
}else{
qrCode.innerHTML = `
<img src="${url}${inputValue}">`;
qrCode.classList.add("active");
}
})
// Add event listener to input field
input.addEventListener("input", ()=>{
var inputValue = input.value.replace(/\s+/g, ""); // Remove all spaces
if(!inputValue){
qrCode.innerHTML = "";
qrCode.classList.remove("active");
}
})
input.addEventListener("keypress", function(event){
if(event.keyCode === 13){
var inputValue = input.value.replace(/\s+/g, ""); // Remove all spaces
if(!inputValue){
qrCode.innerHTML = "";
qrCode.classList.remove("active");
}else{
qrCode.innerHTML = `
<img src="${url}${inputValue}">`;
qrCode.classList.add("active");
}
}
})