Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q48 How do I sum form field values together?

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'.

Feedback on 'Q48 How do I sum form field values together?'

©2018 Martin Webb