SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    random selection

    hi
    am working on the project atht will be doing some kind of a draw. i want to have number eg
    000001
    000002
    000003
    000004
    000005
    and what i want is for the number to be coming randomly one by one and when a button is clicked, the number tat appeared during the clicking should show
    Power of Knowledge

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i want to have number eg
    000001
    000002
    000003
    000004
    000005
    Code:
    var upperLimit = 20;
    var leadingZeros = "000000"; //6 total digits
    
    for(var i = 0; i < 10; ++i)
    {
    	var num = Math.floor(Math.random() * upperLimit) + 1;  //1-20
    	var numStr = num.toString();
    	var len = numStr.length;
    	document.write("<div>" + leadingZeros.substr(len) + numStr + "</div>");
    }
    when a button is clicked, the number tat appeared during the clicking should show
    Code:
    <html>
    <head><title></title>
    
    <script type="text/javascript">
    
    window.onload=function()
    {
    	document.getElementById("b").onclick = function ()
    	{
    		alert("hello world");
    		document.getElementById("d").innerHTML = "hello world";
    	}
    };
    
    
    </script>
    </head>
    <body>
    
    <input type="button" id="b" value="click me"/>
    <div id="d"></div>
    
    </body>
    </html>

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script>
    var time = 100; // Refresh time in miliseconds;
    var timer;
    
    function startRandomizing() {
    	timer = setInterval("randomize()", time );
    }
    
    function stopRandomizing() {
    	clearInterval(timer);
    }
    
    function randomize() {
    	newNumb = Math.round(Math.random() * 999999);
    	document.getElementById("randomHolder").innerHTML = Math.abs(newNumb);
    }
    
    </script>
    </head>
    
    <body>
    	<div id="randomHolder"></div>
    	<a href="javascript:;" onclick="startRandomizing()">Start Randomizing</a><br />
    	<a href="javascript:;" onclick="stopRandomizing()">Stop Randomizinf</a><br />
    	<a href="javascript:;" onclick="randomize()">Custom Rundomize</a><br />
    </body>
    </html>
    i thing this will help you?
    NOTELAY.COM - Have a nice noty day
    ETA CONSULTING


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •