Home Ask Login Register

Developers Planet

Your answer is one click away!

Sterica St February 2016

Detect text filled by barcode scanner(reader) javascript

The code checks barcodes using a barcode scanner. Search_code is filled by a user (keyboard) , and insert_code is filled automatically by a barcode scanner. Currently, code works if both inputs are introduced in barcode scanner values ​​which is not functional for me.

The code needs to run when:

  1. search_code is entered manually ( keyboard ) and
  2. insert_code is filled automatically by the barcode scanner

var search_code = document.getElementById('search_code');
var insert_code = document.getElementById('insert_code');
var result = document.getElementById('result');
var button = document.getElementById('button');
var audio = new Audio('sound.wav');

// respond to button click
button.onclick = function validate(e) {

  // show verification result:
  if (search_code.value == insert_code.value) {
    result.textContent = 'code ok';
    result.className = "ok";
  } else {
    result.textContent = 'code is not ok';
    result.className = "not-ok";
  // clear input when wrong:
  if (search_code.value !== insert_code.value) {
    insert_code.value = '';
  return false;

function clearField(input) {
  input.value = "";
        <input type="text" name="search_code" onfocus="clearField(this, this.placeholder='');" onblur="this.placeholder='introdu codul'" id="search_code" placeholder="introdu codul" autocomplete="off" value=""/><br/>
        <input type="" name="insert_code" onfocus="clearField(this, this.placeholder='');" onblur="this.placeholder='scaneaza codul'" id="insert_code" placeholder="scaneaza codul" autocomplete="of        


nAviD February 2016

To prevent a textbox from being filled by a bar-code reader simply disable onpaste event .

      $('#search_code').bind("cut copy paste",function(e) {

Post Status

Asked in February 2016
Viewed 2,571 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved