Skip to content

Instantly share code, notes, and snippets.

@liketaurus
Created May 3, 2019 15:09
Show Gist options
  • Save liketaurus/00cb274b28cafd88df07a1c591d51fca to your computer and use it in GitHub Desktop.
Save liketaurus/00cb274b28cafd88df07a1c591d51fca to your computer and use it in GitHub Desktop.
How to generate QR-code using JavaScript
<div>
<input type="text" id="textToQR" />
<button id="GenQR" onclick="makeCode();">Generate QR from text</button>
</div>
<br>
<div id="qrcode" style="width:160px; height:160px; margin-top:15px;"></div>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script src="qrcode.min.js"></script>
<script>
var qrcode = new QRCode("qrcode");
function makeCode () {
var elText = $('#textToQR');
if (!elText.val()) {
alert("Input a text");
elText.focus();
return;
}
qrcode.makeCode(elText.val());
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment