Client side calculation

1. Senior Member
Join Date
Dec 1969
Posts
188

## Client side calculation

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Client side calculation

Since you have ALREADY called parseFloat BEFORE you call function f, it is too late to check for "" as the value.<BR><BR>Further, in your function f you are doing<BR> a.value<BR>but you have already converted the form field&#039s ".value" to a simple number by that point, so that won&#039t work either.<BR><BR>Try just this:<BR><BR>function f(a) { return isNaN(a) ? 0 : a; }<BR><BR>in place of your function f. Leave the rest as shown.<BR><BR>Of course, you could shorten this a lot:<BR><BR>function calculate(formObj)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp ;var total = 0.0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for ( i = 1; i &#060;= 7; ++i )<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var curval = parseFloat( eval("formObj.txt_adj" + i + "_value.value") );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;if ( ! isNaN(val) ) total += val;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;& nbsp;&nbsp;formObj.tot_adj_value.value = total;<BR>}<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•