| 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
|
|
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.
|
 |
 |
|
|
subject: adding numbers
|
|
|