简体   繁体   中英

preventing barcode scanner going to the next input box

I was trying to find some value from database and add to the table using barcode scanner using following code

<div class="form-group m-form__group">
    <label for="exampleInputEmail1">Search by Item name or barcode</label>
    <input type="text"  autofocus class="form-control m-input" id="productSearch"  placeholder="Item ">              
</div>

$( "#productSearch" ).change(function(event) {
    event.preventDefault();
  $.ajax({
          type: "get",
          context: this,
          url: "{!! asset('searchByProductName') !!}",
          dataType: 'json',
          data: { name:this.value },
          success: function(response)
            {
              if ($('#' + response.id).length !== 0)
              { $(this).val("").focus(); return false; }
             var markup = "<tr id="+response.id+"><input type='hidden' name='product_id[]'  value="+response.id+"><td><i class='flaticon-delete-1 delete-row' onclick='deleteRow(this)'></i></td><td>"+response.product_name+"</td><td>"+response.product_unit_price+"</td><td><input type='text' name='quantity[]' class='quantity' value='1'></td><td class='total'>"+response.product_unit_price+"</td><td>"+response.notes+"</td></tr>";

              $("table tbody").append(markup); 


                $(this).val("").focus(); return false; 
              } 
        });     
});

But the problem is as soon as it search the value from the database it adds to the table but the pointer going to next input box which i don't to as i need to continuously add value to the table based on checking from barcode scanner. How do i prevent that?

I had an issue like this on a Belgian phone companies subscription system website, the barcode scanner would also include a tab at the end of it!

I used JS to disable the tab key! Can't remember if I somehow restricted it to text in the text box or not (I think I did), but the JS would be something like this (this is all from memory btw):

$('#some-barcode-input').on('keyup', function(e){ 
    var code = e.keyCode || e.which;
    if(code == 9) { // 9 is the tab key
        return false;
    }
});

If keyup doesn't work it might be .change() or similar. Give it a try!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM