Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To 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 December 14th, 2006, 12:21 PM
Authorized User
 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calculate textbox totals

I'm doing a school project and I'm trying to add up several text boxes, however some of them are blank and when I calculate them I get a NaN result. Here is my code:

qty1= parseFloat(document.form1.qty_prt.value)
qty2= parseFloat(document.form1.qty_mon.value)
qty3= parseFloat(document.form1.qty_comp.value)
sub_tot=parseFloat(document.form1.subt.value)
tax_tot=parseFloat(document.form1.tax.value)
grand_tot=parseFloat(document.form1.grandt.value)
qty_tot=eval(qty1+qty2+qty3)
alert("quantity is " + qty_tot)

 
Old December 18th, 2006, 01:03 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

hsi,
you just check empty before write

if(document.form1.qty_prt.value!=""){
qty1= parseFloat(document.form1.qty_prt.value)
}else{
qty1=0;
}

surendran
(Anything is Possible)
http://ssuren.spaces.msn.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Report totals rwahdan BOOK: Access 2003 VBA Programmer's Reference 2 February 5th, 2008 03:56 AM
Help with totals rsm42 ASP.NET 1.0 and 1.1 Basics 0 December 15th, 2006 01:18 PM
Totals not accurate! dba123 Reporting Services 1 February 5th, 2006 10:53 PM
Grouping and totals btado XSLT 3 June 22nd, 2005 01:08 AM
Totals bjackman Access 1 February 8th, 2004 09:27 PM





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