samaswin samaswin - 6 months ago 477
Javascript Question

Barcode scanner for html5 and jquery application

I am using Jquery and html for a project. It is a static web application. I need a jquery that reads barcode scanner's barcode from products. The barcode need to be scanned without displaying the code in any of the textbox in the screen. Someone please gibe me some ideas or provide me the link for plugins (if any) to overcome this. Thanks in advance.

Answer

Try this code. I assum that you know about the Jquery. Run this code and type anything from the keyboard while focusing the web page and hit enter key. If this works barcode reader do the same. Configure your barcode reader to pass enter key at the end of code reading. Jquery library

<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script>

Jquery

 $(document).ready(function() {
        var barcode="";
    $(document).keydown(function(e) {

        var code = (e.keyCode ? e.keyCode : e.which);
        if(code==13)// Enter key hit
        {
            alert(barcode);
        }
        else if(code==9)// Tab key hit
        {
            alert(barcode);
        }
        else
        {
            barcode=barcode+String.fromCharCode(code);
        }
    });

    });