Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 3 of 3

02102009, 05:02 PM #1
 Join Date
 Jan 2009
 Posts
 5
 Thanks
 0
 Thanked 0 Times in 0 Posts
EAN/ISBN13 check digit verification
Hi again,
As noted in my last post I've been trying to teach myself javascript over the last few weeks in order to build a script that can perform check digit verification. Also again, my apologies up front for any glaring newbie mistakes. Any help is VERY MUCH appreciated!!!
How I'd like it to work: When a user has entered an EAN number (13 digits, all numbers) in a text field (called "InsertRecordEAN") and leaves this field (onblur, I believe) the script will run, checking it's last digit/check digit against what I've calcucated it should be. If the check digit is incorrect an alert box will pop up saying so, and when they click OK it highlights the incorrect value, not letting them leave that field until it's corrected.
I've learned quite a lot from your posts in the last couple days, and everything I have below SEEMS like it should work, but I get nothing. Any ideas, at all?
Thanks in advance!!!!!!
d
Code:<html> <head> <script type="text/javascript"> <! > </script> <script type="text/javascript"> <! function ErrorAlert() { document.getElementByName("InsertRecordEAN").onblur = alert("The EAN you entered is incorrect, please reenter it.") document.getElementByName("InsertRecordEAN").focus(); } > </script> <script type="javascript"> <! //**seems to be held up by UserEAN not getting passed to function** function EANCheck(UserEAN) { //2 parse EAN and converted to num except m (var m is check digit supplied by user) var a = parseInt(UserEAN.charAt(UserEAN.length13)); //digit1 var b = parseInt(UserEAN.charAt(UserEAN.length12)); //digit2 var c = parseInt(UserEAN.charAt(UserEAN.length11)); //digit3 var d = parseInt(UserEAN.charAt(UserEAN.length10)); //digit4 var e = parseInt(UserEAN.charAt(UserEAN.length9)); //digit5 var f = parseInt(UserEAN.charAt(UserEAN.length8)); //digit6 var g = parseInt(UserEAN.charAt(UserEAN.length7)); //digit7 var h = parseInt(UserEAN.charAt(UserEAN.length6)); //digit8 var i = parseInt(UserEAN.charAt(UserEAN.length5)); //digit9 var j = parseInt(UserEAN.charAt(UserEAN.length4)); //digit10 var k = parseInt(UserEAN.charAt(UserEAN.length3)); //digit11 var l = parseInt(UserEAN.charAt(UserEAN.length2)); //digit12 var m = parseInt(UserEAN.charAt(UserEAN.length1)); //digit13 //3 multiply each digit against weighting factors to get extended value var a1 =(a * 1); var b1 =(b * 3); var c1 =(c * 1); var d1 =(d * 3); var e1 =(e * 1); var f1 =(f * 3); var g1 =(g * 1); var h1 =(h * 3); var i1 =(i * 1); var j1 =(i * 3); var k1 =(i * 1); var l1 =(i * 3); //4 sum extended values var iSum=(a1+b1+c1+d1+e1+f1+g1+h1+i1+j1+k1+l1); //5&6 divide sum by 10, returning the remainder var iDiv=(iSum % 10); //7 multiply remainder by 10 var By10=(iDiv * 10); //8 subtract remainder from step 7 from "10" (this is check digit if remainder=0 check=0) var CheckD=(10  By10); //"CheckD" is the calculated check digit to compare to user input. if (CheckD != m) { ErrorAlert(); } } //If EANCheck is true allow them to tab to next field. //If EANCheck is false, execute ErrorAlert() & set the focus back on the EAN field. > </script> </head> <body> <form id="caspioform"> EAN:<input type="text" name="InsertRecordEAN" id="InsertRecordEAN" size="30" onblur="EANCheck(this.value)"> <br> Age: <input type="text" id="age" size="30"><br><br> <br> <script type="text/javascript"> <! //test to show initial variables are working, or not guess not, this doesn't seem to work. document.write(a); document.write(b); document.write(c); document.write(d); document.write(e); > </script> </form> </body> </html>
02122009, 02:16 AM
#2
 Join Date
 Jun 2002
 Location
 Between DC and Baltimore In a Cave
 Posts
 2,717
 Thanks
 1
 Thanked 94 Times in 88 Posts
Why the new thread? http://codingforums.com/showthread.php?t=157983
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
02172009, 03:54 PM
#3
 Join Date
 Jan 2009
 Posts
 5
 Thanks
 0
 Thanked 0 Times in 0 Posts
This one works a bit differently, and should be easier and no one had responded to the other one. Since I thought this would be easier to troubleshoot I was hoping I'd get some help and then apply the fixes to the ISBN verification once I figured out how to handle the check digit that could be numerical or text EAN's are all numerical.
Any idea why this one wouldn't work?
Thanks for asking!