<body>
<h2>JavaScript Class</h2>
<p>Check Digit eAN13</p>
<input type="text" id="eAN13" onchange="eanCheckDigit(this.value);">
<p id="demo"></p>
<script>
function eanCheckDigit(s){
var result = 0;
for (counter = s.length-1; counter >=0; counter--){
result = result + parseInt(s.charAt(counter)) * (1+(2*(counter % 2)));
}
document.getElementById("demo").innerHTML = (10 - (result % 10)) % 10;
}
</script>
</body>
</html>
// Credit goes to FAHIM JAMAL VAI
No comments:
Post a Comment