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
Benefits of the PNG Image Format
Benefits of the PNG Image Format

The PNG format was designed to replace the antiquated GIF format, and to some extent, the TIFF format. It u...

Next Article
Code 39 Barcode Generation
Code 39 Barcode Generation

I read this kind of funny story about a kid who got himself into a little...

Do you need imaging tools for your next project?

Explore Our SDKs