Hi,
I’m trying to obtain a random number taking from a variable and then using it to generate a username with a number random in the end, example “alexander.paladines55”.
In php project I normally use: <dmx-value id="myNumber" value="<?php echo(rand(100000000,999999999)) ?>"></dmx-value>
Now in NodeJS I’m trying to obtain a random number from javascript:
<script>
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;}
document.getElementById("numberRand").value = getRndInteger(1,99);
</script>
“numbRand” is a text input because I don’t know how to pass it into UI variable. The above works at half.
The script is placed it at end of a content page, only in the page where a actually need it
When I first time open the content page, the random number is generating into input value, but when I refresh the page I get “0” value, like if the script do not found the element to update value. No error on browser console.
How I can pass the result of the script into a UI variable <dmx-value id="var1"></dmx-value>, or if maybe exist another elegant way to generate a random number and place it into a variable or text input at least.
I’m was trying to put it into Static Event with getRndInteger(1,99) but I can’t get it works.
Hi, thanks for answer.
I’m using mysql in node project.
I have this simple inputs:
Then the username is autogenerate using these to fields plus the random number:
Like I said before I used php into value to generate random number, but in node I only see the chance to generate the number in script and then later capture that number. And this is the only thing that I could make it to works.
I don’t know if there are a elegant way to do it, maybe a custom formatter, but this function is something that will be use in a couple of time, so, something simple in UI will be enought.