Hello there,

I have a problem that I have been trying to resolve for several days, but I am very much stuck. Here is the situation.

This issue concerns an 'ORDER' page, where the user can select a product by scanning a barcode (part of a POS system). This system uses PHP pages, a MySQL database, and jQuery for user-interaction.

So, here goes the input field that exists on the page:

HTML Code:
HTML Code:
<p><input type="text" id="barcode" name="barcode" size="10" /></p>
This element receives automatic focus upon loading the page, and the barcode scanner is used to get the barcode. jQuery is used to see if the code is fully loaded:

Code JavaScript:
$("#barcode").keyup(function(){
	getid = $("#barcode").val();
	if (getid.lastIndexOf("M") > 0)
	{
		location.href = 'sale.php?product='+getid;
	}
});
Explanation: an 'M' at the end of the (numeric) barcode triggers this mechanism. This is just a simple trick to make sure this is not triggered prematurely.

Now, the very WEIRD thing is that when I scan a product, this is automatically added *twice*. This happens often, but not always. This happens more in Firefox than in Chrome. This does NOT happen when I manually type the exact same barcode, only when the scanner is used. After hours of searching I found that this is what causes the problem. When I use the barcode scanner, the browser makes an extra HTTP request. With the Live HTTP Headers add-on in Firefox, I was able to notice that this is what happens:

BARCODE SCANNER IS USED:
Code:
#request# GET http://site/sale.php?product=1305M
#request# GET http://site/sale.php?product=1305M
GET /sale.php?product=1305M
#request# GET http://site/sale.php?product=1305M
MANUALLY TYPING THE SAME CODE:
Code:
#request# GET http://site/sale.php?product=1305M
GET /sale.php?product=1305M
#request# GET http://site/sale.php?product=1305M
So for some reason there is one extra request when the scanner is used. But... WHY?!! And how to fix this this?? I have been trying to answer this question for a while now but I really do not get it. Also, these #request# lines from the LIVE HTTP HEADERS are supposedly skipped (that is why they are commented out), but they definitely make a difference so this explains even less what is going on...

Anybody any idea?!

NOTE: This is most likely not a javascript issue but a browser issue, but I was not sure where else to place this...