javascript addition

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

javascript addition

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Thanks feyd... hey where have you been?? I missed ya man!
Post Reply