Skip to main content

Any ideas why this code isn't working when added to an expression on a data label with Literal ticked?


It's supposed to generate a random alphanumeric and return the value to the data label to be displayed.... I just get a blank..


<span id = "result"></span>

<script type = "text/javascript">

var characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"+
"abcdefghiklmnopqrstuvwxyz";
var word = "";
while (word.length < 5) {  // 5 characters in result
var rand = Math.floor(Math.random() * characters.length);
addchar = characters.substring(rand,rand+1);
if (word.length == 0 && addchar >= 0 && addchar <=9) {  // first character must be a letter (optional)
}
else {word += addchar}
}
document.getElementById("result").innerHTML = word;

</script>


I tested the code via an online HTML tester and it works, but just doesn't in k2.... any ideas?

Originally i tried in K2 designer with an expression using the Random function, but it is limited. I need a Fixed length alphanumeric, is this possible with K2 Deisgner?

Thanks all

Be the first to reply!

Reply