•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,826 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,972 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 621 | Replies: 5
![]() |
•
•
Join Date: Apr 2008
Posts: 29
Reputation:
Rep Power: 1
Solved Threads: 0
this is a dice game by using form to display
it have 3 dices in the function
but when i win, it cant extra money.
it have 3 dices in the function
but when i win, it cant extra money.
<html>
<head>
<script>
function init()
{
bal=2000;
form1.balance.value=bal;
form1.balance.disabled=true;
form1.bynum.disabled=true;
form1.buy.disabled=true;
form1.status.disabled=true;
}
function restart()
{
form1.balance.disabled=false;
form1.bynum.disabled=false;
form1.buy.disabled=false;
form1.status.disabled=false;
}
function roll()
{
var s=Math.floor(Math.random()*15)+3;
form1.status.value=s;
if(form1.bynum.value==s)
form1.balance.value + form1.buy.value;
else
form1.balance.value -= form1.buy.value;
}
function quit()
{
alert("Thanks for playing. Good Bye");
return init();
}
</script>
</head>
<body onLoad="init()">
<form name="form1">
<table border="1">
<tr>
<td>Balance:</td><td colspan="4"><input type="text" name="balance"></td>
<td>Buy:</td>
<td>Status</td>
</tr>
<tr>
<td>By number</td>
<td colspan="4"><select name="bynum">
<script>
for(i=3; i<19;i++)
document.write("<option>" + i +"</option>");
</script>
</select>
</td>
<td><input type="text" name="buy"></td>
<td rowspan="2"><textarea name="status"></textarea></td>
</tr>
<tr>
<td>odd or even:</td>
<td>odd:</td><td><p onClick="roll()";><input type="radio" name="choose"></td>
<td>Even:</td><td><p onClick="roll()";><input type="radio" name="choose"></td>
</tr>
<tr>
<td></td><td><input type="button" value="Restart" OnClick="restart()"></td>
<td></td><td><input type="button" value="Roll" onClick="roll()"></td>
<td></td><td><input type="button" value="Quit" OnClick="quit()"></td>
</tr>
</table>
</form>
</body>
</html>•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
If you want to add numbers, try
total = parseInt(form1.balance.value) + parseInt(form1.buy.value); Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: About Lamp
- Next Thread: collapse/expand table row



Linear Mode