gardanni
10-17-2005, 07:50 PM
I have a simple web form with several fields, and want to dynamically calculate the total when the visitor moves from one field to another. I find that when I use the addition operator (+), the fields are concatenated instead of added. (That is to say, values 1 and 2 in the form are showed as 12 instead of 3.) My test with other operators (ie, *) shows that the variables can indeed be treated as numeric values. Is there a different operator I should be using to force values to be added?
For reference, the script is below and the code of my form is below that.
Thanks!
---------
function addem2(frm2) { frm2.grandtotal.value = frm2.v01.value + fm2.v02.value }
---------
<form name="frm2" method="get">
<input type="TEXT" name="v01" value="" size="6" maxlength="5" onChange="addem2(this.form)"><br>
<input name="v02" type="TEXT" id="v02" onChange="addem2(this.form)" value="" size="6" maxlength="5"><br>
<input type="TEXT" name="grandtotal" value="" size="6">
</form>
For reference, the script is below and the code of my form is below that.
Thanks!
---------
function addem2(frm2) { frm2.grandtotal.value = frm2.v01.value + fm2.v02.value }
---------
<form name="frm2" method="get">
<input type="TEXT" name="v01" value="" size="6" maxlength="5" onChange="addem2(this.form)"><br>
<input name="v02" type="TEXT" id="v02" onChange="addem2(this.form)" value="" size="6" maxlength="5"><br>
<input type="TEXT" name="grandtotal" value="" size="6">
</form>