Reputation: 3
I have a javascript that creates a random number and I need to place this number as a value for the input element. This is the script I have:
<script type="text/javascript">
function randomNumber (00000,99999)
{
m = parseInt(m);
n = parseInt(n);
return Math.floor( Math.random() * (n - m + 1) ) + m;
}
</script>
But actually my task is to generate a random number between 00000 and 99999 and then to post it as a value to input element. I've searched for the answer but haven't find how to place the random value...
Upvotes: 0
Views: 1239
Reputation: 3397
To set an input, you can use this :
document.getElementById('yourInput').value = YourRandomNumber;
in your function jsFiddle here
function randomNumber (m,n)
{
m = parseInt(m);
n = parseInt(n);
YourRandomNumber = Math.floor( Math.random() * (n - m + 1) ) + m;
document.getElementById('yourInput').value = YourRandomNumber;
}
and when you call, randomNumber (00000,99999);
Upvotes: 1