Generating a Random Number for HTML -
i trying generate random number between 2 values can changed whatever choose. on load of page, want number shown in body of site.
thanks!
your question pretty vague needed here javascript solution generates random number between 2 variables , sets <div>
content that:
fiddle: http://jsfiddle.net/benedictlewis/xmpgr/
js:
var link = document.getelementbyid('getnumber'); // gets link link.onclick = getnumber; // runs function on click function getnumber() { var minnumber = 0; // minimum number want var maxnumber = 100; // maximum number want var randomnumber = math.floor(math.random() * (maxnumber + 1) + minnumber); // generates random number $('#mynumber').html(randomnumber); // sets content of <div> number return false; // returns false tidy }
html:
<div id="mynumber"></div> <!-- number appear in here --> <a href="no-javascript.html" id="getnumber">get number</a> <!-- link number. if user has no js enabled redirect no-javascript.html -->
Comments
Post a Comment