Hello,
If your barcode scanner acts like a keyboard (for example if you can just scan something into a text document), you can use this javascript to grab the data and filter it against normal keyboard input.
Barcode scanners that support the keyboard wedge feature usually dump a line break after entering a barcode - this script takes advantage of that. If your scanner does not do this, simply take out the e.which == 13 && section of that if (but then if you type four numbers very quickly, this could be interpreted as a barcode scan).
the function handleScan would be your own javascript function that handles the scan. You can use ajax or regular form submission from here to get the barcode to your back-end.
Let me know if I can be of any further help!
var barcode = '';
var bc_timeout;
function getScan(e) {
if (e.which == 13 && barcode.length > 5) {
handleScan(barcode);
barcode = '';
e.preventDefault();
return;
}
var keynum = e.keyCode;
var keychar = String.fromCharCode(keynum);
if (!isNaN(keychar)) {
barcode += keychar;
clearTimeout(bc_timeout);
bc_timeout = setTimeout('emptyBarcode()', 50);
}
}
function emptyBarcode() {
barcode = '';
}