...

View Full Version : Creating Calculator- Troubles because + is doing this (7+3 = 73) instead of (7+3=10)



KELS!
10-15-2006, 12:43 AM
I've looked around a lot and all I've found is that I'm supposed to concatenate the string becuase JS is reading the + sign as just putting them together. Not adding.



function formula()
{
var costa = calculator.costa.value;
var profita = calculator.profita.value;
var yeilda = calculator.yeilda.value;
var answer = Math.abs((costa + profita) / yeilda);
calculator.ans.value = answer;
return false;
}

The variable I'm having the trouble with is ANSWER. costa and profita are supposed to be added together, not just put next to each other.

Here is the calculator: http://qualitygrainservices.com/calc.php

I hope I gave enough information for everyone to sorta know what I'm having trouble with. If not please say something so I can give you more!

mrhoo
10-15-2006, 12:53 AM
Form values are always returned as strings,
convert them to number format before math operations with
parseFloat(value) or Number(value)

KELS!
10-15-2006, 12:54 AM
Form values are always returned as strings,
convert them to number format before math operations with
parseFloat(value) or Number(value)

Whoa. I have no idea what you said. I'm sorry! I just started all of this today...

KELS!
10-15-2006, 01:35 AM
Nevermind. I figured it out. I still have no idea what you were talking about though. Lol.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum