I have this code working:
<!DOCTYPE html>
<html>
<head>
<script type = "text/javascript"></script>
</head>
<body>
<img id='qrcode' src=''>
<button onclick="newQR()">Gerar QRcode</button>
<script> function newQR() {
var x = Math.floor((Math.random() * 99999999999999999) + 1);
document.getElementById('qrcode').src = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + x + "&size=[500]x[500]&ecc=L&qzone=4&format=png";
}
</script>
</body>
Now I am trying to divide creating a js file and putting the script code inside. Right now my code is:
html file
<!DOCTYPE html>
<html>
<head>
<script type = "text/javascript"></script>
</head>
<body>
<img id='qrcode' src=''>
<button onclick="newQR()">Gerar QRcode</button>
<script type = "text/javascript" src = "js/script.js"></script>
</body>
</html>
javascript file (that it is inside a paste called js)
function newQR() {
var x = Math.floor((Math.random() * 99999999999999999) + 1);
document.getElementById('qrcode').src = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + x + "&size=[500]x[500]&ecc=L&qzone=4&format=png";
}
Why it is not working anymore?
See Question&Answers more detail:os