Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run it? #6

Open
ZAWYED opened this issue Feb 27, 2023 · 2 comments
Open

How to run it? #6

ZAWYED opened this issue Feb 27, 2023 · 2 comments

Comments

@ZAWYED
Copy link

ZAWYED commented Feb 27, 2023

Hello sir, I've been searching for something like this and I'm thrilled to have found it. Thank you so much! As a newcomer to coding, I tried searching on Google for instructions on running a JS code, but I'm having difficulty. Could you please help me with running this data matrix code generator? I would greatly appreciate your assistance. Thank you in advance!

@0horaa
Copy link

0horaa commented Jul 11, 2023

Hello @ZAWYED, what's up? I just implemented it, it's actually pretty simple to use. Take a look at the example below:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Datamatrix test</title>
</head>
<body>
    <div id="datamatrix-container">

    </div>
    <p>Your content...</p>

    <!-- Remember import datamatrix script before your scripts -->
    <script src="datamatrix.min.js"></script>

    <script>
        const datamatrixContainer = document.querySelector("#datamatrix-container");

        const datamatrixNode = DATAMatrix("1234");

        datamatrixContainer.appendChild(datamatrixNode);
    </script>
</body>
</html>

The DATAMatrix function returns an svg Element that you can use for any purpose. In the previous example I simply created a datamatrix and displayed it inside the div with the id "datamatrix-container".

Don't forget to download datamatrix.min.js and place it in the correct folder.

@ChuckTerry
Copy link

@ZAWYED - What exactly are you trying to accomplish? Here's a remix of @0horaa 's reply that adds an input textarea, button, and event listener, if that helps out any.

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Datamatrix test</title>
</head>
<body>
    <div id="datamatrix-container"></div>
    <textarea id="input-string">Text to Encode</textarea>
    <button type="button" id="encode">Encode</button>

    <!-- Remember import datamatrix script before your scripts -->
    <script src="https://cdn.jsdelivr.net/gh/datalog/datamatrix-svg@latest/datamatrix.min.js"></script>

    <script>
        document.querySelector('#encode').addEventListener('click', () => {
            const datamatrixContainer = document.querySelector('#datamatrix-container');
            const string = document.querySelector('#input-string').value;
            const datamatrixNode = DATAMatrix(string);
            datamatrixContainer.appendChild(datamatrixNode);
        });
    </script>
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants