PDA

View Full Version : Lottery Numbers Generator Issues in IE



shellshock30
11-17-2010, 10:34 PM
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?

djr33
11-18-2010, 01:46 AM
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.

shellshock30
11-18-2010, 04:43 AM
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

jscheuer1
11-18-2010, 06:42 AM
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:

Further testing shows this is not the entire solution.


<!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>

jscheuer1
11-19-2010, 01:29 PM
OK, this one appears bulletproof on that IE bug:


<!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>