aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes adding numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "adding numbers " Watch "adding numbers " New topic
Author

adding numbers

sweta naidu
Greenhorn

Joined: Nov 02, 2004
Posts: 25
i am facing a problem while populating calculated value in the text field.
here is my js function
function Total()
{
document.forms[0].p_phase.value = parseInt(document.forms[0].p_scope.value) +
parseInt(document.forms[0].p_plan.value )+ parseInt(document.forms[0].p_design.value)
+ parseInt(document.forms[0].p_build.value )+ parseInt(document.forms[0].p_anal.value)
+ parseInt(document.forms[0].p_systest.value )+ parseInt(document.forms[0].p_uat.value)

}

this code works if values entered for all the fileds if not it displays NaN. but i want this to function even if some values entered.

Thanks,
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
you need to check for isNaN before adding or set a default value of 0 to the fields.

Eric
KasiMurugan Ramasamy
Ranch Hand

Joined: Jan 30, 2005
Posts: 125
Hi

For each value, if follow the below like logic you could get the desired results.

var currentVal = document.forms[0].p_scope.value;
if( currentVal.length >0 && !isNaN( currentVal) )
total = total + parseInt( currentVal );


Thanks & Regards
Kasimurugan (SCJP1.4, SCBCD1.3), Preparing SCWCD1.4
sweta naidu
Greenhorn

Joined: Nov 02, 2004
Posts: 25
Thanks. it solved my problem.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: adding numbers
 
Similar Threads
show/hide formfields
JSP Action Buttons freez after returning from ajax call
howto make my code shorter ?
How to disable all form elements
portlet submit using javascript