1

I am not a programmer and what I have "written" is mostly copied from others, However I'. in a dire need of a solution. What I have in mind is comparing two arrays, one of which is filled with strings from and the other is filled by a bluetooth QR reader, so that I can compare the two arrays and mark duplicate values as "found" (it's an inventory system). However when I try to read a QR code into an input it automatically redirects me to a new browser page. (the code i scanned is no URL, its just an inventory number in a ###/### format) My input works perfectly when I use keyboard.. and since key logger claims that the only button the reader has is "13" I assumed it would behave just like a regular "13" Enter.. when I abused a slower computer at work I found out that it actually does as intended, writes the number into the input, "submits" it by pressing enter.. and then it redirects away.. any ideas to stop it from doing so? Thanks, Michal


    <input type="file" id="file-selector" accept=".csv">
    <button id="btn-upload-csv">Read CSV</button>
  <br>
    <input id="scanID">
    <button id="buttonS" onClick="spustit()">Spustit</button>
    <button id="buttonR" onClick="reset()">Reset</button>
    <p id="pole"></p>
  <p id="pole2"></p>
  <table id="tbl-data"></table>
    <script>
    let btn_upload = document.getElementById("btn-upload-csv").addEventListener("click", ()=>{
    Papa.parse(document.getElementById("file-selector").files[0],{download: true,
    header: false,
    complete: function(results){console.log(results);
            }   
        });
    });
var cele=[];
function spustit() //Zeptat se jak zakázat prázdné scany  array.filter?
{
  nove=[(document.getElementById("scanID").value)];
  cele.push(nove);
  document.getElementById("pole").innerHTML=cele;
  document.getElementById("scanID").value="";
}
function reset()
{
  cele=[];
  document.getElementById("pole").innerHTML=cele;
}
var input = document.getElementById("scanID");
input.addEventListener("keyup", function(event) {
  if (event.keyCode === 13) {
   event.preventDefault();
   spustit();
  }
});
const fileSelector = document.getElementById("file-selector");
fileSelector.addEventListener('change', (event) => {
  const fileList = event.target.files;
  console.log(fileList);
});
</script>
  • What do you mean by new browserpage, which page? – Raqha Oct 19 '20 at 13:04
  • 1
    sorry my mistake, It's a new window, I tested on Chrome,Opera, Mozilla, Edge Explorer.. all behave the same. – Michal Masopust Oct 19 '20 at 19:21
  • And now that I tried it again.. I was wrong.. it's not only a new tab, it searches for the text i scanned on bing. Why Bing of all things? Google is set as the default SE. – Michal Masopust Oct 20 '20 at 06:26
  • Oh this fact is interesting, that it search something with bing. Bing is the Microsoft SE, so f.e. when you search something in Cortana, the result comes on Bing. Does it open in Edge aswell? – Raqha Oct 20 '20 at 06:58
  • Ok, another thought on that. Maybe your Bluetooth Scanner, has a own driver and everytime you scan a QR-Code, it will execute something in the Background, without anything implemented by you. So, does this all with the new page happens, even if you dont use your Scanner for your Webpage? – Raqha Oct 20 '20 at 07:02
  • 1
    as far as I tested it happens on my webpage as well as on other pages (I tried on w3schools) where i scan into an "input field" but it works fine when i scan to a "search bar" on multiple sites.. but their code is too comlex for me to understand. And when i scan outside of browser ( to a text file for example, it does as expected, just text and CR or LF or both depending or settings.. no browser, no new windows no other characters – Michal Masopust Oct 20 '20 at 08:52
  • Can you add references to the code youre using? Like pages where you found them. – Raqha Oct 20 '20 at 10:38
  • 1)https://www.w3schools.com/html/html_form_input_types.asp 2)https://www.youtube.com/watch?v=WrI19Qp6Uoc 3)https://www.w3schools.com/howto/howto_js_trigger_button_enter.asp 4)https://web.dev/read-files/ – Michal Masopust Oct 20 '20 at 11:09

1 Answers1

0

You probably either need to change the End Character of your Scanner. When you use some type of Scanner (QR-Code,Barcode etc...), the Scanner will provide end Character. Normally they're something like CR+LF (Carriage Return + Line Feed more on that here). You need to change that to just CR (If this is the case with your scanner).

Or a simple solution to this problem is, that you just ignore this end character. You do this with a simple eventListener:

input.addEventListener('keydown', function(event) {
if( event.keyCode == 13 || event.keyCode == 17)
event.preventDefault();
});

Keycodes:13 = Enter, 17 = CR

Kindest Regards Raqha

Raqha
  • 754
  • 4
  • 17
  • thaks for the tip, sadly neiher changing to "suffix+CR" nor adding the event listener seem to fix the issue. – Michal Masopust Oct 20 '20 at 06:22
  • @MichalMasopust Oh, it makes sense now. This is just a "fix" when its only happening on Chrome, and as you mentioned, its the same on any Browser. – Raqha Oct 20 '20 at 06:55