简体   繁体   中英

Dymo label does not print when button clicked

Im trying to make a webform to put in text and print it out on the label. So far the webform and the printing have been working, but somehow I changed something and it is not printing anymore. The button stopped working and its been hours for me trying things to get it to work again(I started all over several times). Can someone help me and take a look?

The code does not give any errors whatsoever.

This is my PrintLabel.JS

    (function()
{
    // called when the document completly loaded
    function onload()
    {
        var printButton = document.getElementById('printButton');


        // prints the label
        printButton.onclick = function()
        {
            var txtMerk = document.getElementById('txtMerk');
            var txtModel = document.getElementById('txtModel');
            var txtOnderdeel = document.getElementById('txtOnderdeel');
            var txtOnderdeelNr = document.getElementById('txtOnderdeelnr');
            var txtPrijs = document.getElementById('txtPrijs');
            var txtLoc = document.getElementById('txtLocatie');
            var txtDonor = document.getElementById('txtDonor');

            try
            {
                // open label
                var BestandTePrinten = document.getElementById('txtMerk').value + '.label';
                $.get(BestandTePrinten, function (labelXml) {
                    var label = dymo.label.framework.openLabelXml(labelXml);

                    // set label text

                    // select printer to print on
                    // for simplicity sake just use the first LabelWriter printer
                    var printers = dymo.label.framework.getPrinters();
                    if (printers.length == 0)
                        throw "No DYMO printers are installed. Install DYMO printers.";

                    var printerName = "";
                    for (var i = 0; i < printers.length; ++i) {
                        var printer = printers[i];
                        if (printer.printerType == "LabelWriterPrinter") {
                            printerName = printer.name;
                            break;
                        }
                    }

                    if (printerName == "")
                        throw "No LabelWriter printers found. Install LabelWriter printer";

                    // finally print the label
                    label.setObjectText('txtMerk', txtMerk.value);
                    label.setObjectText('txtModel', txtModel.value);
                    label.setObjectText('txtOnderdeel', txtOnderdeel.value);
                    label.setObjectText('txtOnderdeelnr', txtOnderdeelNr.value);
                    label.setObjectText('txtLoc', txtLoc.value);
                    label.setObjectText('txtPrijs', "€" + txtPrijs.value);
                    label.setObjectText('txtDonor', txtDonor.value);
                    label.print(printerName);
                });
            }
            catch(e)
            {
                alert(e.message || e);
            }
        }
    };

   function initTests()
    {
        if(dymo.label.framework.init)
        {
            //dymo.label.framework.trace = true;
            dymo.label.framework.init(onload);
        } else {
            onload();
        }
    }

    // register onload event
    if (window.addEventListener)
        window.addEventListener("load", initTests, false);
    else if (window.attachEvent)
        window.attachEvent("onload", initTests);
    else
        window.onload = initTests;

} ());

This is my index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Print A label</title> 
        <script src = "jquery-3.4.1.js" type="text/javascript" charset="UTF-8"></script>
        <script src = "DYMO.Label.Framework.latest.js" type="text/javascript" charset="UTF-8"></script>
        <script src = "PrintLabel.js" type="text/javascript" charset="UTF-8"></script>
        <link rel="stylesheet" href="style.css">

    </head>

    <body>


        <div id="container">
            <div class="form-style-9">
                <center><h2>Print Label</h2> </center>
                <ul>
                    <li>
                        <select class="field-style field-split align-left" id="txtMerk">
                            <option value="Volkswagen">Volkswagen</option>
                            <option value="Audi">Audi</option>
                            <option value="Seat">Seat</option>
                            <option value="Skoda">Skoda</option>
                            <option value="Mercedes">Mercedes</option>
                            <option value="BMW">BMW</option>
                            <option value="Fiat">Fiat</option>
                            <option value="Ford">Ford</option>
                            <option value="Peugeot">Peugeot</option>
                            <option value="Citroen">Citroën</option>
                            <option value="Volvo">Volvo</option>
                        </select>
                        <input type="text" class="field-style field-split align-right" id="txtModel" placeholder="Model">
                    </li>
                    <li>
                        <input type="text" id="txtOnderdeel" placeholder="Onderdeel" class="field-style field-split align-left">
                        <input type="text" id="txtOnderdeelnr" placeholder="Onderdeelnummer" class="field-style field-split align-right">
                    </li>
                    <li>
                        <input type="text" id="txtLocatie" value="" class="field-style field-split align-left" placeholder="Locatie 2-1-A1">
                        <input type="text" id="txtPrijs" value="" class="field-style field-split align-right" placeholder="Prijs">
                    </li>
                    <li>
                        <textarea name="txtDonor" class="field-style" placeholder="Oorsprong onderdeel"></textarea>
                    </li>
                    <li>
                        <button id="printButton">Print</button>                
                    </li>
                </ul>
            </div>

        </div>

    </body> 

</html>

First visible check - try to update:

(function()
{
    // called when the document completly loaded
    function onload()
    {

to

$(function()
{
    // called when the document completely loaded
    //  function onload()
    {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM