www.webdeveloper.com
Results 1 to 4 of 4

Thread: HELP! Adding two numbers from input boxes, to a third output.

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Question HELP! Adding two numbers from input boxes, to a third output.

    Currently it adds them without converting the input to integers. So. Ill just give you what I have. Help is very much appreciated.

    :

    <html>
    <head>
    <title>
    COMSC 100 Assignment 6 by Tom Gonser 1401658
    </title>
    <script type="text/javascript">
    // copy/paste the following three lines after the script tag in EVERY program
    function getInputAsText(_id){return document.getElementById(_id).value}
    function getInputAsNumber(_id){return parseFloat(document.getElementById(_id).value)}
    function setOutput(_id, _value){document.getElementById(_id).value = _value}
    function calculate()
    {
    var firstNum, lastNum, fullNum
    firstNum = getInputAsNumber("firstNumBox")
    lastNum = getInputAsNumber("lastNumBox")
    fullNum = firstNum + lastNum
    setOutput("fullNumBox", fullNum)
    }
    </script>
    </head>
    <body>
    Instructions:<br />
    Type two numbers, and click computate. <br />
    Something will happen.<br />
    <br />
    Input Values:<br />
    Numbah Won <input id="firstNumBox" type="number" /><br />
    Numbah Too <input id="lastNumBox" type="number" /><br />
    <input type="submit" value="Computate" onclick="calculate()" />
    <br />
    Output value:<br />
    Here ya go: <input id="fullNumBox" type="number" />
    </body>
    </html>

  2. #2
    Join Date
    Nov 2012
    Posts
    2
    Dead forum is dead?

  3. #3
    Join Date
    Mar 2009
    Posts
    452
    fullNum = parseInt(firstNum) + parseInt(lastNum)

  4. #4
    Join Date
    Dec 2012
    Posts
    1
    Hey you might not be glad cause i have no answers but questions how to make my code work... on same subject. HOpe you dont mind
    Or if you find resolution let me know:

    script>
    function zbroji(broj1,broj2)
    {
    var c = broj1 + broj2;
    document.write("<br>Zbroj te 2 vrijednosti je:"+c);

    var a =document.getElementById('broj1').value;
    var b =document.getElementById('broj2').value;
    var a =parseInt(a);
    var b =parseInt(b);
    }

    function pomnozi(broj1,broj2)
    {
    var d = broj1 + broj2;
    document.write("<br>Mnozenjem ta dva broja dobijemo:"+d);

    var a =document.getElementById('broj1').value;
    var b =document.getElementById('broj2').value;
    var a =parseInt(a);
    var b =parseInt(b);
    }


    function ispis()
    {
    document.getElementById('ispis').innerHTML("zbroji(a,b)","pomnozi(a,b)")
    }

    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles