Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 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
    Regular Coder
    Join Date
    Mar 2006
    Posts
    725
    Thanks
    35
    Thanked 132 Times in 123 Posts
    Form values are always returned as strings,
    convert them to number format before math operations with
    parseFloat(value) or Number(value)

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote 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...

  • #4
    New Coder
    Join Date
    Oct 2006
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Nevermind. I figured it out. I still have no idea what you were talking about though. Lol.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •