Hi,
I have the folloing user macro, which uses javascript to calculate the EAN13 check digit.
<div id="result"></div>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#result').text('$paramEAN13'+getLastEan13Digit('$paramEAN13'));
});
function getLastEan13Digit(ean) {
if (!ean || ean.length !== 12) {return 'ERROR';};
const multiply = [1, 3];
let total = 0;
ean.split('').forEach((letter, index) => {
total += parseInt(letter, 10) * multiply[index % 2];
})
const base10Superior = Math.ceil(total / 10) * 10;
return base10Superior - total;
};
</script>
This works absolutely fine.
But if I use the same macro more than once on a page, it only renders the first one.
Thanks for any help
Reto