lindell / JsBarcode

Barcode generation library written in JavaScript that works in both the browser and on Node.js
http://lindell.me/JsBarcode
MIT License
5.49k stars 1.11k forks source link

Dynamic Barcode generation #208

Open SCOMAC1959 opened 6 years ago

SCOMAC1959 commented 6 years ago

Is it possible to replace the barcode information with information from another div?

Something like: JsBarcode("#barcode3", "SK000007", { format: "CODE39", displayValue: true, });

Replacing the SK000007 with content of another div such as this jQuery code?: $('#div2').html($('#div1').html());

If so how might that be done?

laferil commented 6 years ago

This is what I use to dynamically generate sheets of different barcodes.

Each item is added with an HTML template with the following. I replace the #UPC# with the actual value when generating the file.

<svg class="barcode"
  jsbarcode-format="upc"
  jsbarcode-value="#UPC#"
  jsbarcode-textmargin="0"
  jsbarcode-fontoptions="bold">
</svg>

Then at the end of the file I added this simple script line which initializes all .barcode classes.

<script>
    JsBarcode(".barcode").init();
</script>