Web Analytics Made Easy -
StatCounter Creating Calculator- Troubles because + is doing this (7+3 = 73) instead of (7+3=10) - CodingForum

Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating Calculator- Troubles because + is doing this (7+3 = 73) instead of (7+3=10)

    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.

    Code:
    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!

  • #2
    Form values are always returned as strings,
    convert them to number format before math operations with
    parseFloat(value) or Number(value)

    Comment


    • #3
      Originally posted by mrhoo View Post
      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...

      Comment


      • #4
        Nevermind. I figured it out. I still have no idea what you were talking about though. Lol.

        Comment

        Working...
        X