User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

need help with + value

  #1  
Jun 4th, 2008
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.
<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>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 120
Reputation: sillyboy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
sillyboy sillyboy is offline Offline
Junior Poster

Re: need help with + value

  #2  
Jun 4th, 2008
I didn't really look through the code too thoroughly, but:

form1.balance.value + form1.buy.value;

did you want += here?
Reply With Quote  
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

Re: need help with + value

  #3  
Jun 5th, 2008
is still the same. it can extra the money
Reply With Quote  
Join Date: Mar 2007
Posts: 120
Reputation: sillyboy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
sillyboy sillyboy is offline Offline
Junior Poster

Re: need help with + value

  #4  
Jun 5th, 2008
That fix worked for me. I checked it in firefox, the only problem with += would be string concatenation, but it was definitely adding digits for me...
Reply With Quote  
Join Date: Apr 2008
Posts: 29
Reputation: Visualogic is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Visualogic Visualogic is offline Offline
Light Poster

Re: need help with + value

  #5  
Jun 6th, 2008
oh?
lets me try
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: need help with + value

  #6  
Jun 6th, 2008
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*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC