Why isn't this Javascript code working in Data Label Expression?

  • 2 December 2016
  • 0 replies
  • 0 views

Userlevel 3
Badge +16

Hi,

 

Got this code which generetas a random alphanumeric number, which i want to return and display in a Data Label, but it wont work, anyone able to tell me why?

I'm using the usual Data Label with literal ticked and using the following in an expression:

 

<span id = "result"></span>
<script type = "text/javascript">
var characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"+
"abcdefghiklmnopqrstuvwxyz";
var word = "";
while (word.length < 5)
var rand = Math.floor(Math.random() * characters.length);
addchar = characters.substring(rand,rand+1);
if (word.length == 0 && addchar >= 0 && addchar <=9)
else {word += addchar}
document.getElementById("result").innerHTML = word;
</script>

The result is an empty box... Any ideas why?

 

I know the code is fine because i tested it on an online javascript tester and it generates a random code as i want, it just doesn't work in K2.

 

I originally tried to build this in K2 Designer, but the Random function is limited, i need Fixed length random alphanumeric...

 

Any help appreciated guys and gals.


0 replies

Be the first to reply!

Reply