Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q48 How do I sum form field values together?

irt.org | Knowledge Base | JavaScript | Form 6 | Q48 [ previous next ]

Q48 How do I sum form field values together?

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


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.