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.
Asked
Active
Viewed 8.1k times
12
-
Do you physically scan it or do you want to scan soft copy of bar code? Are you using Barcode reader – Sajitha Rathnayake Apr 01 '14 at 06:05
-
1I have a barcode scanner which I used to scan the products – samaswin Apr 01 '14 at 06:18
3 Answers
19
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);
}
});
});

Sajitha Rathnayake
- 1,688
- 3
- 26
- 47
-
-
I have faced an issue with this code. When I am scanning the special characters the ASCII character are varied based on the browser. – samaswin Aug 27 '14 at 08:36
-
-
Please visit this page. I think this will help you. http://www.bennadel.com/blog/2389-detecting-and-canceling-key-combo-events-with-jquery.htm – Sajitha Rathnayake Aug 27 '14 at 09:27
-
Please ignor my http://stackoverflow.com/a/22778311/2345900 answer. Do not down vate me for that answer. I have corrected it here – Sajitha Rathnayake Jun 02 '16 at 06:32
0
May be you can try this https://code.google.com/p/jquery-barcodelistener/ .
It catches the barcode scanner's output and gives to you as a parameter

Mohammed Imran N
- 1,279
- 1
- 11
- 26
0
I found this quite old but pretty good post which was working fine with my hardware.
I have implemented it into a jquery plugin: jquery-code-scanner, you can try it here to see if it works with your code reader.
$ bower install jquery-code-scanner
<script src="js/jquery.min.js"></script>
<script src="js/jquery-code-scanner.js"></script>
<!-- ... -->
<input type="text" id="code-scan">
$('#code-scan').codeScanner();
Don't hesitate to create issues or PRs on the project.

Pierre de LESPINAY
- 44,700
- 57
- 210
- 307