Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2004, 06:06 AM
Registered User
 
Join Date: May 2004
Location: Kansas City, MO, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Math on a Form

I am trying to get total to calc on a form.
I have three fields that I want to add together and display in the Total field.

Sub-Total:
Shipping:
Sales Tax:

Total:

On the first three fields I use onChange="CalcTotal()"

For this function I am using:
 SubAmt = document.form1.SubTotal.value;
 ShipAmt = document.form1.Ship.value;
 TaxAmt = document.form1.Tax.value;
 GrandTotal = SubAmt + ShipAmt + TaxAmt;
 document.form1.TotalPrice.value = GrandTotal;

If I enter 1 in each of the three fields my total is 111. How do I make it return 3?

Thanks,
David


 
Old May 12th, 2004, 09:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try this:

GrandTotal = parseInt(SubAmt) + parseInt(ShipAmt) + parseInt(TaxAmt);


 
Old May 12th, 2004, 11:04 AM
Registered User
 
Join Date: May 2004
Location: Kansas City, MO, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do I maintain the decimal point? ie 1.25 + 1.25 + 1.25 = 3.75 not 4?

thanks,
David

 
Old May 12th, 2004, 12:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try parseFloat or search for Math.round.
 
Old May 12th, 2004, 05:01 PM
Registered User
 
Join Date: May 2004
Location: Kansas City, MO, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ParseFloat worked!

thanks for the help
david





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with Math.pow trryan5 Java Basics 4 July 27th, 2007 06:12 AM
Math operators nguyendh BOOK: Ivor Horton's Beginning Visual C++ 2005 1 June 25th, 2006 01:35 AM
Math question dparsons ASP.NET 1.0 and 1.1 Professional 5 June 14th, 2006 02:31 PM
Math Namespace transtar C# 3 February 12th, 2006 09:50 AM
math.floor casper BOOK: Beginning Java 2 1 October 29th, 2004 11:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.