Php or JavaScript calculator needed ASAP

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

    Php or JavaScript calculator needed ASAP

    I have taught myself programming in certain languages over the years. Still haven't quite figured out out how to make this calculator work the way I want it. Here is the formula that I want the calculator to perform.
    I want it to be in a column type setup like so

    Left side:
    Carbs: <input box> (should times by two)
    Calories: <input box>
    Protein: <input box> (should times by three)

    Right side of form:
    Total: ( Total of all three on left side times 2.66 )

    Anyone that can get me a script for this I would greatly appreciate it.

    #2
    PHP Code:
    <script type="text/javascript">
    function 
    somethingElse()
    {
    var 
    cb document.getElementById("carbs").value;
    var 
    cl document.getElementById("calories").value;
    var 
    document.getElementById("protein").value;
    document.getElementById("output").value = ((cb*2)+cl+(p*3))*2.66;
    }
    </
    script>
    <
    form>
    carbs: <input type="text" id="carbs" onkeyup="somethingElse();"/>
    calories: <input type="text" id="calories" onkeyup="somethingElse();"/>
    protein: <input type="text" id="protein" onkeyup="somethingElse();"/>
    Result: <input type="text" id="output"/>
    </
    form
    Last edited by something else; 16.01.13, 03:30.

    Comment


      #3
      Thank you so much I learn something new everyday in programming. I'm going to try one more thing with this if I can't figure it out you mind if I ask you.
      Last edited by Thanks48; 16.01.13, 02:48.

      Comment


        #4
        Sorry i messed up the first code i will edit it

        Sure

        Comment

        Working...
        X