How to use the Javascript provided by the SDK for creating barcodes in HTML?

The HTML Barcode SDK trial package includes the scripts and HTML source code for the Code 39 barcode. The HTML and scripts help to illustrate how to create professional quality barcodes on a web page. The registered package includes the scripts for all the supported barcodes mentioned above. Files included

The SDK contains different subdirectories with examples and scripts for creating different types of barcodes. In each of the subdirectory, the HTML and Javascript files are provided. For example, in the "code39" subdirectory, the "csshtmlCode39Barcode.html" illustrates how to use the Javascript function provided by the HTML Barcode SDK for creating a Code 39 barcode.

Tutorial on creating a Code 39 barcode using the HTML Barcode SDK

1. First create a HTML file. In the file, include the appropriate barcode script. For the Code 39 barcode, this script is located in the "code39/js" subdirectory. The HTML code below assumes the Code 39 Javascript is copied to a subdirectory named "js" of the HTML file.



<script type="text/javascript" 
src="js/connectcode-javascript-code39.js">
</script>



2. After including the script, the following Javascript function can be called to generate the barcode. In the function below, we are creating a Code 39 barcode and the data to be used is specified in the first parameter. We will not go into the details of the rest of the parameters. For details on the parameters, refer to the HTML Barcode SDK Properties section.



DrawHTMLBarcode_Code39("12345678",1,"yes","in", 0,3,1,3,"bottom","center", "","black","white");



The Javascript function automatically generates and returns HTML tags and code to be included into the HTML source file. For example, if the HTML file includes the following <div> tags.



<div id="barcodecontainer" style="width:5in">
<div id="barcode" >12345678</div>
</div>



The following Javascript function call will replace the data with the generated barcode. document.getElementById("barcode").innerHTML



=DrawHTMLBarcode_Code39("12345678",1,"yes","in",
0,3,1,3,"bottom","center", "","black","white");



We suggest using a <div> container as in the case of "barcodecontainer" as shown above. Simply allocate enough space in the container for including the actual barcode. The container is useful as it will be used by the SDK to determine the alignment of the barcode and the human readable text. In our case above, five inches of space is allocated for the barcode container.

3. We have included the full contents of the HTML file for creating the Code39 barcode below. The get_object Javascript function is simply a wrapper to ensure cross browser compatibility.

HTML Code 39 Source File



Other useful pages :