Page 1 of 1

javascript addition

Posted: Thu Jan 12, 2006 1:44 pm
by Luke
This is going to sound stupid... I haven't ever been too big on javascript, so I don't know how to do this...
Basic math??? How do you add numbers

I am trying something like:

Code: Select all

subtotal = document.form.field.value
tax = subtotal * 0.0725
total = tax + subtotal
document.write(subtotal)
And I am getting all wrong answers... what gives?

Posted: Thu Jan 12, 2006 1:51 pm
by feyd
subtotal is considered a string, not an integer.

Code: Select all

subtotal = new Number(document.form.field.value);
and a suggestion: always place semicolons at the end of a statement in Javascript.

Posted: Thu Jan 12, 2006 2:38 pm
by Luke
Thanks feyd... hey where have you been?? I missed ya man!