JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 14th, 2010, 12:03 PM
bwgrudt1484 bwgrudt1484 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2010
Posts: 1 bwgrudt1484 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 46 sec
Reputation Power: 0
Need Help Debugging Script/Error in Script - How do I get a field of checkboxes to add and multiply?

Hi, I need to be able to have a field of checkboxes that can be highlighted to show a per person price for various goods and services. I then need to be able to multiply that by a numeric text field that will give an overall event price. After that, I need to be able to multiply a number (hours) by a dropdown box (number of bartenders) and multiply THAT by an hourly rate dropdown for two specific labor types (tipped or nontipped), and add it to the event price for a total price.

I am not at all experienced with JS, I know a decent bit of html, but the code I have is snippets of other codes I've picked up. This code is for my own business, not a commercial venture. It does not function as it should, and I have no basis of knowledge as to why not... Here's what I have so far on the event price side, haven't tried the labor side yet:


Code:
<script language="javascript">
var sum = 0;
var multiplier = document.getElementById('myMulti').value;
var roundedSum = roundNumber(sum,2)

function roundNumber(sum, 2) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function addition(param)    
	{ 
  
if (param.checked == true)       
 	sum += parseFloat(param.value);   
else        
	sum += -parseFloat(param.value);   

 document.getElementById("totalSpan").innerText = roundedSum;  
	 }
</script>

		<form id="form1">
			Party Size: <input type="text" id="myMulti" /> <br />
			<input type="checkbox" value="0.10" onclick="addition(this)"/>Iced Tea<br />
			<input type="checkbox" value="0.10" onclick="addition(this)"/>Glassware<br />
			<input type="checkbox" value="0.25" onclick="addition(this)"/>Fruit<br />
			<input type="checkbox" value="0.50" onclick="addition(this)"/>Soda<br />
			
			Total: <span id="totalSpan">0</span>
		</form>

Reply With Quote
  #2  
Old April 14th, 2010, 01:15 PM
mecanicu mecanicu is offline
anonymous
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 244 mecanicu User rank is Private First Class (20 - 50 Reputation Level)mecanicu User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 12 h 21 m 10 sec
Reputation Power: 13
Code snippet

At a first glance I see this
Code:
function roundNumber(sum, 2) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

Where the second parameter is missing, but used as is actually there.
I believe this is the right code:
Code:
function roundNumber(sum, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}


hope it helps

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Need Help Debugging Script/Error in Script - How do I get a field of checkboxes to add and multiply?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap