You are here: irt.org | FAQ | JavaScript | Form | 6 | Q48 [ previous next ]
Because form field values are always strings it is necessary to convert them to numbers before summing them. For example if you do:
var a = '1'; var b = '2'; var c = a + b;
Then the variable c would contain '12'.
The Netscape recommended solution is to do the following:
var a = '1'; var b = '2'; var c = (a-0) + (b-0);
Now the variable c would contain '3'.