Create and display a QR code with a URL.

by amindunited

HTML

<div id="qrcode"></div>
    <script src="https://cdn.jsdelivr.net/gh/davidshimjs/qrcodejs/qrcode.min.js"></script>

JavaScript

// Ensure the DOM is fully loaded before trying to access elements
    document.addEventListener('DOMContentLoaded', function() {
        var qrcode = new QRCode(document.getElementById("qrcode"), {
            text: "https://forms.gle/cg2AZHSwZafycNUz8", // The data to encode (e.g., a URL, text)
            width: 128,                 // Width of the QR code in pixels
            height: 128,                // Height of the QR code in pixels
            colorDark : "#000000",      // Color of the dark modules
            colorLight : "#ffffff",     // Color of the light modules
            correctLevel : QRCode.CorrectLevel.H // Error correction level (L, M, Q, H)
        });

        // You can also update the QR code later:
        // qrcode.makeCode("New data to encode");
    });