Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Barcode Scanner throwing off Javascript

Status
Not open for further replies.

Gatorajc

MIS
Mar 1, 2002
423
US
Im having a wierd problem that may or may not be related to Javascript. I created the following script. It is a mixture of Javascript and ASP.

The function is supposed to read a text field after the 13th character it either increments a text box or throws an alert saying the number was entered to many times. Works great when the number is typed. The problem is when when the number is put in with a barcode scanner. It will throw the alert message. But only for a second and keep running the script. Can someone have a look at this and tell me if Im doing something wrong w/the script. This way Ill know if it is the scanner doing something, in which case I have go down that road.
Code:
<SCRIPT LANGUAGE="JavaScript">
Test = 0;
Count = <%=BarcodeCount%>;
SubmitCnt = 0;
Qty = new Array();
TotalQty = new Array();

for (i = 1; i <= Count; i++)
{
   Qty[i] = 0;
   TotalQty[i] = WorkQueue['Qty_' + [i]].value;
   WorkQueue['ScanTotal_' + [i]].value = 0;
}

function CheckBarCode(formname)
{
   if (formname.DOS.value.length == 13)
   {
      barcodelist = formname.barcodelist.value;
      barcodecount = formname.barcodecount.value;
      barcode = barcodelist.split(" ");
	
      for (i = 0; i < barcodecount; i++)
      {	
         if (formname['Bar_' + barcode[i]].value == formname.DOS.value)
	 {
	    Qty[i+1]++;
	    if (Qty[i+1] > TotalQty[i+1])
	    {
	       Sendalert()
	    }
	    else
	    {
	        formname['ScanTotal_' + [i+1]].value = Qty[i+1];
		SubmitCnt ++;
		if (SubmitCnt == <%=TotalQty%>)
		{
		formname.submit();
		}
	     }

	  }
	
	}

   formname.DOS.value = "";
}

}
function Sendalert()
{
   alert("To many products scanned");
   return false;
}
</script>

AJ
[americanflag]

Do you feel lucky?


 
I tried to understand the logic behind your code. I failed.

If you type the number in manually and it doesn't "error"... then, using the barcode scanner (which is supposed to mimic typing) in the same conditions it "errors"... then definately the first place to look is the barcode scanner!

Put an alert at the beginning of the function you call that alerts you to the actual barcode being scanned in (by the scanner) and also the length of the barcode (so you know that "hidden" characters aren't sneaking in).

Jeff

 
Thanks Jeff,

Yea I have to be better about commenting first.

I fixed it. I took the alert out and went with something else.Works great now. The scanner probably has some return character at the end of its input causing the problem.

Thanks for your time.

AJ
[americanflag]

Do you feel lucky?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top