Results 1 to 5 of 5

Thread: Lottery Numbers Generator Issues in IE

  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Lottery Numbers Generator Issues in IE

    Hi All, The generator works fine in Firefox but when I test it in IE it functions properly for the first couple rolls but at the third time it keeps going and won't stop. How do I get it to function properly in IE?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You have to give us a link to your page for us to help. And this sounds like it might be a homework assignment. Please be aware that we don't do homework for you, though we may offer advice if you have done most of the work yourself.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry for not being specific. It's not homework, I'm working on a website. The code actually came from this site. All I did was re-work my button to run off this script. Other than the button, nothing in the script was changed.

    http://www.dynamicdrive.com/dynamicindex12/lottery.htm

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Oddly enough even the demo page for this script exhibits the same problem. So I was tempted to say it was simply a buggy script and leave it at that. It is buggy, but I wondered why. I installed it on a fresh page though and it was fine. It does have a lot of unnecessarily globally exposed variables and other poor coding practices. Perhaps fixing it up would help:

    Edit: Further testing shows this is not the entire solution.


    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    .a1 {
    	position: relative;
    	font: normal 20px verdana, sans-serif;
    	color: #888;
    }
    #ltable {
    	border-width: 0;
    	height: 50px;
    	width: 250px;
    }
    #ltable td {
    	text-align: center;
    }
    </style>
    
    <script>
    
    /*****************************************
    * Lottery Picker (By Kurt at kurt.grigg@virgin.net)
    * Featured on/available at http://www.dynamicdrive.com/
    * Modified by DynamicDrive.com for below config options
    * This notice must stay intact for use.
    *****************************************/
    
    function lotto(){
    	var totalnumbers=4, //input total numbers to generate
    	lowerbound=1,   //input lower bound for each random number
    	upperbound=49,  //input upper bound for each random number
    	B=' ', i, j, LottoNumbers=[], RandomNumber, X, B, OutPut;	
    	for (i = 1; i <= totalnumbers; ++i){
    	RandomNumber = Math.round(lowerbound+Math.random()*(upperbound-lowerbound));
    		for (j = 1; j <= totalnumbers; j){
    			if (RandomNumber == LottoNumbers[j]){
    				RandomNumber=Math.round(lowerbound+Math.random()*(upperbound-lowerbound));
    				j=0;
    			}
    			++j;
    		}
    		LottoNumbers[i]=RandomNumber;
    	}
    	LottoNumbers=LottoNumbers.toString();
    	X=LottoNumbers.split(',');
    	for (i=0; i < X.length; ++i){
    		X[i]=X[i]+' ';
    		if (X[i].length==2){
    			X[i]='0'+X[i];
    		}
    	} 
    	X=X.sort();
    	for (i=0; i < X.length; ++i){
    		OutPut=B+=X[i];
    	}
    	if (document.getElementById){document.getElementById("layer1").innerHTML=OutPut;}
    	else if (document.all){document.all.layer1.innerHTML=OutPut;}
    	lotto.t = setTimeout(lotto, 20);
    }
    function StOp(){
    	setTimeout(function(){clearTimeout(lotto.t);}, 1000);
    }
    
    </script>
    </head>
    <body>
    <table id="ltable">
    <tr>
    <td>
    <form name=form>
    <input type=button value='Lottery Number Picker' onClick="lotto();StOp()">
    </form>
    <span id=layer1 class=a1>Result</span>
    </td>
    </tr>
    </table>
    </body>
    </html>
    Last edited by jscheuer1; 11-18-2010 at 07:17 AM. Reason: Further testing . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, this one appears bulletproof on that IE bug:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style>
    .a1 {
    	position: relative;
    	font: normal 20px verdana, sans-serif;
    	color: #888;
    }
    #ltable {
    	border-width: 0;
    	height: 50px;
    	width: 250px;
    }
    #ltable td {
    	text-align: center;
    }
    </style>
    
    <script>
    
    /*****************************************
    * Lottery Picker (By Kurt at kurt.grigg@virgin.net)
    * Featured on/available at http://www.dynamicdrive.com/
    * Modified by DynamicDrive.com for below config options
    * This notice must stay intact for use.
    * Modified 11/10 to reduce global exposure and eliminate timeout collisions
    * See: http://www.dynamicdrive.com/forums/showthread.php?p=241758#post241758
    *****************************************/
    
    function lotto(){
    	var totalnumbers = 4, //input total numbers to generate
    	lowerbound = 1,   //input lower bound for each random number
    	upperbound = 49,  //input upper bound for each random number
    	
    	////////////////// No Need to Edit Below Here //////////////////
    	
    	i, j, tmpNumbers = [], randomNumber, X, outPut = ' ', genRand = function(){
    		randomNumber = Math.round(lowerbound + Math.random() * (upperbound - lowerbound));
    	};	
    	for (i = 0; i < totalnumbers; ++i){
    	genRand();
    		for (j = 0; j < totalnumbers; ++j){
    			if (randomNumber === lotto.numbers[j] || randomNumber === tmpNumbers[j]){
    				genRand();
    				j = -1;
    			}
    		}
    		tmpNumbers[i] = randomNumber;
    	}
    	lotto.numbers = tmpNumbers;
    	X = [].concat(lotto.numbers);
    	for(i = 0; i < X.length; ++i){
    		X[i] = X[i] + ' ';
    		if (X[i].length === 2){
    			X[i] = '0' + X[i];
    		}
    	} 
    	for (i = 0; i < X.length; ++i){
    		outPut += X[i];
    	}
    	if (document.getElementById){
    		document.getElementById("layer1").innerHTML = outPut;
    	} else if (document.all){
    		document.all.layer1.innerHTML = outPut;
    	}
    	if(!lotto.t){
    		setTimeout(lotto, 20);
    	} else {
    		lotto.t = false;
    	}
    }
    lotto.numbers = [];
    
    function StOp(){
    	setTimeout(function(){lotto.t = true;}, 1000);
    }
    
    </script>
    </head>
    <body>
    <table id="ltable">
    <tr>
    <td>
    <form name=form>
    <input type=button value="Lottery Number Picker" onclick="lotto();StOp();">
    </form>
    <span id=layer1 class=a1>Result</span>
    </td>
    </tr>
    </table>
    
    </body>
    </html>
    Last edited by jscheuer1; 11-19-2010 at 02:59 PM. Reason: a bug had crept in, fixed
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •