Writing Code 39 Barcodes with Javascript

April 25, 2008 Lou Franco

I previously showed how easy it is to generate Code 39 Barcodes using DotImage, now I want to show you how to do it in pure JavaScript.

I wanted to make it easy to deploy so I don't use images. Luckily, 1D barcodes are easy to make with just colored table cells, so I just generate a one row table with a column for each bar.  I set the width of the column to be the width of the bar and then color it either black or white.

Here's a page where you generate barcodes with just JavaScript. The code is attached to this entry.

To use it, just add Barcode.js to your site, include it in a script tag, then use the AtalasoftBarcode39 object to draw the barcode (there is a file called BarcodeTest.html in the zip file to show an example).  Here's some sample code:

    function writeBC(s)
        var bc = new AtalasoftBarcode39(s);
        document.getElementById('bcArea').innerHTML =
            bc.getBarcode(50, 2, 8);



The three arguments to getBarcode are the height and the widths of the narrow bars, and the width of the wide bars.


About the Author

Lou Franco

Lou is the former Vice President of Product Development at Atalasoft.

Follow on Twitter More Content by Lou Franco
Previous Article
DotPdf: Making your own shapes

Posted by Steve Hawley January 23, 2012 Comments ...

Next Article
Robotron and OOP

Many years back, joe holt and I pulled the ROMs from a Robotron machine that...

Try any of our Imaging SDKs free for 30 days with Full Support

Download Now