Search Your Query

QR code Generator

 To create a QR code using HTML and JavaScript, you can use a JavaScript library like `qrcode.js`. Here’s a simple example of how to integrate it into an HTML page:


1. **Include the Library**: You need to include the `qrcode.js` library. You can either download it or use a CDN. 


2. **Write the HTML and JavaScript Code**: Use the following code to create a QR code:


```html

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>QR Code Generator</title>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>

</head>

<body>

    <h1>QR Code Generator</h1>

    <input type="text" id="text-input" placeholder="Enter text here" />

    <button onclick="generateQRCode()">Generate QR Code</button>

    <div id="qrcode"></div>


    <script>

        function generateQRCode() {

            const text = document.getElementById('text-input').value;

            document.getElementById('qrcode').innerHTML = ''; // Clear previous QR code

            if (text) {

                $('#qrcode').qrcode({ text: text });

            }

        }

    </script>

</body>

</html>

```


### Explanation:

- **Libraries**: The code includes jQuery and a QR code generation plugin for jQuery.

- **Input Field**: A text input where users can enter the data to be encoded.

- **Button**: A button that triggers the QR code generation.

- **QR Code Display**: A `div` where the QR code will be displayed.

- **JavaScript Function**: `generateQRCode` reads the input value and generates the QR code, clearing any previous codes first.


**Note**: Ensure you have internet access to load the libraries from the CDN, or you can host the libraries locally if preferred.