I try to send a random number into a tag in my script to test how my page will react.
So here's what i've got.
<script>
display_number = 1.5684651 ;
display = display_number;
function DIS_EN() {
var num = display;
var n = num.toFixed(2);
document.getElementById("display_value").innerHTML = n;
}
</script>
Rignt now the display_number
is fixed to 1.5684651
, what I want is to get a random number in the display_number
tag. This information will come from an external page and it will vary so that's why I want a random number.
How can I do that? I know I can use a Math.random
to generate a random number but I don't know how to show it in my display_number
tag...
EDIT:
One more thing: I want it to change by itself... I tried setInterval(function(){Math.random},2000)
, but it doesn't seem to work.
EDIT 2:
Here's my latest code, with the setInterval
in it
<script>
setInterval(function(){display_number = Math.floor((Math.random() * 1.0E+10) + 1);}, 2000);
display = display_number;
function DIS_EN() {
var num = display;
var n = num.toFixed(2);
document.getElementById("display_value").innerHTML = n;
}
</script>
I get a new value everytime I refresh the page only when I add the setInterval
I get a blank page...