-1

I am writing a web application that needs to take input from a barcode scanner.

Currently, the system printing the barcode is adding a '\13' (I think a carriage return) to the beginning of the value. Thus, whenever the barcode is scanned for example into firefox, the cursor jumps to the search bar and puts the value there rather than in my text field.

I definitely cannot modify the printed barcodes themselves. Is there a way to prevent the barcode from changing the input field from my text box to the search bar?

Thanks!

  • sending a carrier return is normal, since most barcode scanners pretend to be keyboards to the system, and just send the barcode contents as a sequence of "keystrokes". but the jumping to a different field - no idea on that. – Marc B Jun 10 '14 at 18:25
  • 1
    "\13".charCodeAt(0); gives 11 (0x0b), which is Vertical Tab in ascii. http://stackoverflow.com/questions/3380538/what-is-a-vertical-tab. That might explain why it changes focus. – akatakritos Jun 10 '14 at 18:44

2 Answers2

2

Hitting Enter usually does not "jump" to some different input, but instead does submit the formular in which the focus is currently located. Any following keypresses will go to the reloaded page, where they might end up in some autofocused search bar or so.

To prevent such, install a keypress listener on the barcode input field and call .preventDefault() on the event when it was the enter key. See Prevent users from submitting a form by hitting Enter for details.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

Look for the barcode scanner model, generally after reading a barcode barcode scanner can be set to do some key board action like entering tab or pressing enter key. Which is called carrier return(CR). Recommend to go trough the user guide where you can get solution. There you can just set no suffix where you will only get barcode text.