JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 15th, 1999, 12:30 PM
Tag Heuer
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Hey there!

Ok, Since I posted my last querry, I have had a lot of progress with my script.

I still have to make a few changes to it.

1 - I am still trying to make the calc. automatically calculate the price as soon as you type in the quantity.

2 - I am also having a problem with the price. The set price is $30.90, but when you type in a quantity of 3, 6, or 9 it is $.01 off.

If anyone can help I would appreciate it.
Here is the script that I have

<script LANGUAGE="JavaScript">

function dp(price)
{
string = "" + price;
number = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.01';
if (number == 1)
return string + '00';
if (number == 2)
return string + '0';
if (number > 3)
return string.substring(0,string.length-number+3);
return string;
}

function calculate()
{
document.calcform.total1.value = dp((document.calcform.price1.value)*(document.calcform.quantity1.value))

}

</script>
</head>
<body bgcolor="#FFFFFF" onload="calculate">

<center><form name="calcform" action="http://www./mailto:YOU@YOURSITE.COM" method="post"></center>

<center><table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="600" >
<tr>
<td>QUANTITY</td>

<td>PRICE</td>

<td>TOTAL</td>
</tr>

<tr>
<td><input type="text" name="quantity1" size="5" ONCHANGE="calculate()"></td>

<td>$30.90/ea<input type=hidden name="price1" value="30.90" ONCHANGE="calculate()"></td>

<td><input type="text" name="total1" size="10"></td>
</tr>

<tr>
<td></td>

<td><input type="button" Value="Calculate" ONCLICK="calculate()"></td>

<td></td>
</tr>
</table></center>

<center></form></center>

</body>
</html>

Reply With Quote
  #2  
Old December 18th, 1999, 02:31 PM
Conner Smith
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I had the same problem with my java calculator. The unit price was $9.95, but multiples of 3, 6 and 7 caused the total to end in .9999999 - always .0000001 shy of being correct.

I played with it for a while and finally suggested to the client that we price the product at an even $10 rather than $9.95.

I hated doing that. It felt like DEFEAT! If someone can explain why it does this, I would really like to know.

Thanks.

Reply With Quote
  #3  
Old December 27th, 1999, 12:16 PM
time2brew
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
1. your ONCHANGE event is case sensitive. change it to onChange and it will probably work
2. as for your math calc problem. I can't tell you why it happens accept that it is a computer. an easy fool proof solution would be:
num=Math.round(num*100)/100;

that would shift the cents to an integer, round up or down (in this case up) to the nearest integer, and then shift back to cents.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Javascript Order Calculator


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT