jbinky
April 5, 2011, 7:13am
1
Not sure why it not working correctly. Keeps hanging up when click on “Begin Drawing” and nothing populates in the Output. Thank you for your help.
Here’s my code:
<html>
<head>
<title>Loops</title>
<script type=“text/javascript” src=“random.js”>
</script>
<script type=“text/javascript”>
function Drawing()
{
//variable declarations
var Pick,Picks;
var Pick1,Pick2,Pick3,Pick4;
var Roll1,Roll2,Roll3,Roll4;
var Count;
var Profit;
//input section
Pick1=parseFloat(document.LottoForm.txtPicks.value);
Pick2=parseFloat(document.LottoForm.txtPicks.value);
Pick3=parseFloat(document.LottoForm.txtPicks.value);
Pick4=parseFloat(document.LottoForm.txtPicks.value);
//calculations
Count=0;
while(Pick1!=Roll1 || Pick2!=Roll2 || Pick3!=Roll3 || Pick4!=Roll4)
{
Count++;
Roll1=RandomInt(0,9);
Roll2=RandomInt(0,9);
Roll3=RandomInt(0,9);
Roll4=RandomInt(0,9);
}
Profit=10000-Count;
document.LottoForm.txtPicks.value=(Roll1+" “+Roll2+” “+Roll3+” "+Roll4);
document.LottoForm.txtPicks.value=(Count);
//output section
document.LottoForm.txtPickOut.value=Pick.toFixed(2);
document.LottoForm.txtPicksOut.value=Picks.toFixed(2);
document.LottoForm.txtProfitOut.value=Profit.toFixed(2);
}
</script>
</head>
<body bgcolor="gold" style="color:darkblue">
<u><h1 style="text-align:center">Pick-4 Lotto</h1></u>
<form name="LottoForm" style="text-align:center">
<br /><br />
Pick-4 Lottery Number: <input type="text" name="txtPicks" size=5 value=""/>
<input type="text" name="txtPicks" size=5 value=""/>
<input type="text" name="txtPicks" size=5 value=""/>
<input type="text" name="txtPicks" size=5 value=""/> Enter 4 Single-Digit Numbers
<br /><br />
Click on the button to perform Pick-4 drawing until sequence appear
<br />
<input type="button" value="Click Here to Begin Drawing" onClick="Drawing();"/>
<br /><br />
Number of Picks: <input type="text" name="txtPicksOut" size=10 value=""/>
<br /><br />
Pick: <input type="text" name="txtPickOut" size=10 value=""/>
Net Profit: <input type="text" name="txtProfitOut" size=20 value=""/>
</body>
</html>
You’re not addressing the form elements properly:
Pick1=parseFloat(document.LottoForm.txtPicks[B][0][/B].value);
Pick2=parseFloat(document.LottoForm.txtPicks[B][1][/B].value);
Pick3=parseFloat(document.LottoForm.txtPicks[B][2][/B].value);
Pick4=parseFloat(document.LottoForm.txtPicks[B][3][/B].value);
Also your form isn’t closed.
jbinky
April 5, 2011, 2:37pm
4
Not sure why the “Pick-4 Lottery Numbers” doesn’t get transferred to the “Pick” box when clicked on button.
Am I missing something?
<html>
<head>
<title>Loops</title>
<script type="text/javascript" src="random.js">
</script>
<script type="text/javascript">
function Drawing()
{
//variable declarations
var Picks;
var Pick1,Pick2,Pick3,Pick4;
var Roll1,Roll2,Roll3,Roll4;
var Count;
var Profit;
//input section
Pick1=parseFloat(document.LottoForm.txtPicks[0].value);
Pick2=parseFloat(document.LottoForm.txtPicks[1].value);
Pick3=parseFloat(document.LottoForm.txtPicks[2].value);
Pick4=parseFloat(document.LottoForm.txtPicks[3].value);
//calculations
Count=0;
while(Pick1!=Roll1 || Pick2!=Roll2 || Pick3!=Roll3 || Pick4!=Roll4)
{
Count++;
Roll1=RandomInt(0,9);
Roll2=RandomInt(0,9);
Roll3=RandomInt(0,9);
Roll4=RandomInt(0,9);
}
Profit=10000-Count;
document.LottoForm.txtPicks.value=(Roll1+" "+Roll2+" "+Roll3+" "+Roll4);
document.LottoForm.txtPicks.value=(Count);
//output section
document.LottoForm.txtCountOut.value=Count.toFixed();
document.LottoForm.txtProfitOut.value=Profit.toFixed(2);
}
</script>
</head>
<body bgcolor="gold" style="color:darkblue">
<u><h1 style="text-align:center">Pick-4 Lotto</h1></u>
<form name="LottoForm" style="text-align:center">
<br /><br />
Pick-4 Lottery Number: <input type="text" name="txtPicks" size=5 value=""/>
<input type="text" name="txtPicks" size=5 value=""/>
<input type="text" name="txtPicks" size=5 value=""/>
<input type="text" name="txtPicks" size=5 value=""/> Enter 4 Single-Digit Numbers
<br /><br />
Click on the button to perform Pick-4 drawings until sequence appears
<br />
<input type="button" value="Click Here to Begin Drawing" onClick="Drawing();"/>
<br /><br />
Number of Picks: <input type="text" name="txtCountOut" size=10 value=""/>
<br /><br />
Pick: <input type="text" name="txtPicksOut" size=10 value=""/>
Net Profit: <input type="text" name="txtProfitOut" size=20 value=""/>
</form>
</body>
</html>
Your web browser should tell you that a function is missing from the above.
Do you know where the JavaScript error console is for your web browser?
jbinky
April 5, 2011, 10:51pm
6
That’s the problem, no error is shown when I ran it and I’m using FireFox.
You saw no error in the Error Console ?
jbinky
April 6, 2011, 4:36am
8
Nope. Everything works, but the Pick box didn’t transfer from the top numbers boxes. That’s why I’m confused.
That’s odd, in my test is seems to have worked for me when a suitable randomInt function was in place.
Do you want to link us to a test web page where your problem can be experienced?
jbinky
April 6, 2011, 12:48pm
11
I’m just running it off my laptop. This was my homework for school.
Is there a test web page in this forum where I can do that? Because I will probably ask for more help when I have to do my final project.
jbinky:
I’m just running it off my laptop. This was my homework for school.
Is there a test web page in this forum where I can do that? Because I will probably ask for more help when I have to do my final project.
There are plenty of free web hosts, for example: 110mb.com
What others do people recommend for free hosting?
paul_wilkins:
There are plenty of free web hosts, for example: 110mb.com
What others do people recommend for free hosting?
I use Zymic.com .
They provide a free domain name, php and mysql.
The only support is forum based and live chat, but it’s alright.