how to add a simple calculation

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

    • May 2008
    • 1

    how to add a simple calculation

    I don't have a lot of experience with this. I am trying to add a few formulas to my website but dont know how.

    ex.

    1st Balance = 40,000 (user types this in)

    2nd Balance = 20,000 (user types this in)

    Total balance = 60,000

    this would be an addition of the 1st balance and the 2nd balance
  • Collectors-info
    General

    • Feb 2006
    • 8703

    #2
    Re: how to add a simple calculation

    Would a calculator on the page do the trick, or is there more involved.
    Regards Chris.

    Collectables, Collecting, collectors-info.com

    www.chrismorris.co.uk

    House build project

    Comment

    • Tash717
      Private

      • Apr 2008
      • 1

      #3
      Re: how to add a simple calculation

      I work with dcourt, and what he is trying to do is add two cells together based on different inputs, so someone visiting his site could calculate the total themselves.

      Example:
      1st balance:

      $20,000
      2nd balance$10,000 Total:$30,000 (we want this cell to automatically calculate the values above).


      A simple calculator would work...is there a tool in BlueVoda that will help us, or can we import an excel formula? If we need a claculator, where would we find it?

      Thanks!

      Comment

      • CarbonTerry
        Major General

        • Oct 2005
        • 2620

        #4
        Re: how to add a simple calculation

        Paste the below code into an html box for an online calculator.


        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Untitled Page</title>
        <meta name="GENERATOR" content="Created by BlueVoda">
        </head>
        <body bgcolor="#FFFFFF" text="#000000">
        <div id="bv_" style="position:absolute;left:39px;top:30px;width: 150px;height:150px;z-index:0" align="left">
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Untitled Page</title>
        <meta name="GENERATOR" content="Created by BlueVoda">
        </head>
        <body bgcolor="#FFFFFF" text="#000000">
        <div id="bv_" style="position:absolute;left:39px;top:30px;width: 150px;height:150px;z-index:0" align="left">
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Untitled Page</title>
        <meta name="GENERATOR" content="Created by BlueVoda">
        </head>
        <body bgcolor="#FFFFFF" text="#000000">
        <div id="bv_" style="position:absolute;left:34px;top:34px;width: 150px;height:150px;z-index:0" align="left">
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <html>
        <head>
        <title></title>
        <meta name="keywords" content="">
        <meta name="description" content="">
        <link rel="stylesheet" href="/src/css.css" type="text/css">

        <style>
        <!--
        .btnBlue {
        background-color:CCD3DC;
        border-color:DCE2E9;
        color:19222D;
        font-size : 11px;
        font-family : verdana,arial,helvetica,sans-serif;
        }
        .btnLtBlue {
        background-color:EEEFF1;
        border-color:DCE2E9;
        color:19222D;
        font-size : 11px;
        font-family : verdana,arial,helvetica,sans-serif;
        }
        .btnWhite {
        background-color:ffffff;
        border-color:DCE2E9;
        color:19222D;
        font-size : 11px;
        font-family : verdana,arial,helvetica,sans-serif;
        }
        -->
        </style>
        <script language="JavaScript">
        <!--
        var ci;
        function init() {
        ci = document.calc.input;
        }
        function calculate() {
        ci.value = eval(ci.value);
        }
        function plus() {
        ci.value += '+';
        }
        function minus() {
        ci.value += '-';
        }
        function mult() {
        ci.value += '*';
        }
        function div() {
        ci.value += '/';
        }
        function decimal() {
        ci.value += '.';
        }
        function openp() {
        ci.value += '(';
        }
        function closep() {
        ci.value += ')';
        }
        function num(x) {
        ci.value += x;
        }
        function recip() {
        ci.value = 1/(ci.value);
        }
        function square() {
        ci.value = (ci.value)*(ci.value);
        }
        function cube() {
        ci.value = (ci.value)*(ci.value)*(ci.value);
        }
        function pi() {
        ci.value += Math.PI;
        }
        function plus_or_minus() {
        ci.value *= -1;
        }
        function percent() {
        ci.value *= .01;
        }
        function sqrt() {
        ci.value = Math.sqrt(ci.value);
        }
        function power() {
        var np = prompt("What power do you want? Must be a number!","")
        ci.value = Math.pow(ci.value, np);
        }
        function cos() {
        ci.value = Math.cos(ci.value);
        }
        function sin() {
        ci.value = Math.sin(ci.value);
        }
        function tan() {
        ci.value = Math.tan(ci.value);
        }
        function Round() {
        ci.value = parseInt(ci.value);
        }
        function del() {
        ci.value = ci.value.substring(0, ci.value.length - 1)
        }
        // -->
        </script>

        </head>
        <body onload="init()" leftmargin="20" topmargin="20" marginwidth="20" marginheight="20" bgcolor="#ffffff" text="#000000" link="#006666" vlink="#006666" alink="#ff00ff" background="">
        <div align="center">

        <table class="table1" cellpadding="40" cellspacing="0" border="0">
        <tr>
        <td valign="top" align="center" style="padding-top:30px;padding-bottom:30px">


        <table bgcolor="000000" cellpadding="2" cellspacing="0" border="0">
        <form name="calc">
        <tr>
        <td>
        <table bgcolor="888E96" width="55" height="65" cellspacing="0" cellpadding="5" border="1">
        <tr>
        <td><input type="text" name="input" size="20" maxlength="30"></td>
        <td><input type="button" value=" ^ " onClick="power()" class="btnLtBlue"></td>
        <td><input type="button" value="Del" onClick="del()" class="btnLtBlue"></td>
        <td><input type="button" value=" C " onClick="ci.value = ''; " class="btnLtBlue"></td>
        </tr>
        <tr>
        <td nowrap="1"><input type="button" value=" 1 " class="btnBlue" onClick="num(1)">
        <input type="button" value=" 2 " class="btnBlue" onClick="num(2)">
        <input type="button" value=" 3 " class="btnBlue" onClick="num(3)">
        <input type="button" value=" ( " class="btnLtBlue" onClick="openp()"></td>
        <td><input type="button" value=" + " onClick="plus()" class="btnLtBlue"></td>
        <td><input type="button" value="sqrt" onClick="sqrt()" class="btnLtBlue"></td>
        <td><input type="button" value="Cos" onClick="cos()" class="btnLtBlue"></td>
        </tr>
        <tr>
        <td nowrap="1"><input type="button" value=" 4 " class="btnBlue" onClick="num(4)">
        <input type="button" value=" 5 " class="btnBlue" onClick="num(5)">
        <input type="button" value=" 6 " class="btnBlue" onClick="num(6)">
        <input type="button" name="closeprth" value=" ) " class="btnLtBlue" onClick="closep()"></td>
        <td><input type="button" value=" - " onClick="minus()" class="btnLtBlue"></td>
        <td><input type="button" value=" 1/x" class="btnLtBlue" onClick="recip()"></td>
        <td><input type="button" value="Sin " onClick="sin()" class="btnLtBlue"></td>
        </tr>
        <tr>
        <td nowrap="1"><input type="button" value=" 7 " class="btnBlue" onClick="num(7)">
        <input type="button" value=" 8 " class="btnBlue" onClick="num(">
        <input type="button" value=" 9 " class="btnBlue" onClick="num(9)">
        <input type="button" value=" % " onClick="percent()" class="btnLtBlue"></td>
        <td><input type="button" value=" * " onClick="mult()" class="btnLtBlue"></td>
        <td><button class="btnLtBlue" onClick="square()">&nbsp;x<sup>2</sup>&nbsp;</button></td>
        <td><input type="button" value="Tan " onClick="tan()" class="btnLtBlue"></td>
        </tr>
        <tr>
        <td nowrap="1"><input type="button" value=" 0 " class="btnBlue" onClick="num(0)">
        <input type="button" value=" . " class="btnBlue" onClick="decimal()">
        <input type="button" value=" +/- " onClick="plus_or_minus()" class="btnLtBlue">
        <input class="btnLtBlue" type="button" value=" Pi " onClick="pi()"></td>
        <td><input type="button" value=" / " onClick="div()" class="btnLtBlue"></td>
        <td><button class="btnLtBlue" onClick="cube()">&nbsp;x<sup>3</sup>&nbsp;</button></td>
        <td><input type="button" value=" = " class="btnWhite" onClick="calculate()"></td>
        </tr>
        </table>
        </td>
        </tr>
        </form>
        </table>



        </td>
        </tr>
        </table>
        </div>
        <div align="center">
        <p />
        <p />
        <script type="text/javascript"><!--
        google_ad_client = "pub-0616514424695237";
        google_ad_width = 100;
        google_ad_height = 90;
        google_ad_format = "120x90_0ads_al";
        google_ad_channel ="6335145439";
        google_color_border = "ffffff";
        google_color_bg = "FFFFFF";
        google_color_link = "080878";
        google_color_url = "008000";
        google_color_text = "000000";
        //--></script>
        <script type="text/javascript"
        </script>
        <p />&nbsp;
        </div>



        </script><p />&nbsp;
        </body>
        </html>
        </div>
        </body>
        </html></div>
        </body>
        </html></div>
        </body>
        </html>
        CarbonTerry
        Semper Fi
        Still green...still mean......just not as lean

        Red Hawk Archery
        Zone 5 Photo
        My USMC

        Comment

        • judavvforum
          Major

          • Nov 2007
          • 384

          #5
          Re: how to add a simple calculation

          Terry
          I just installed your calculator script and found that the "8" digit didn't work. I found that in your script above, the "8" digit is missing. This line of code should be: <input type="button" value=" 8 " class="btnBlue" onClick="num(">
          EDIT: The numeral eight & ), still won't show on this post, but works in the corrected coding on my site!
          Last edited by judavvforum; 05-06-2008, 04:30 AM. Reason: correcting script

          Comment

          • Collectors-info
            General

            • Feb 2006
            • 8703

            #6
            Re: how to add a simple calculation

            Hi, slightly simpler one here if any good.

            <html>
            <head>
            <title></title>
            </head>
            <body>
            <form name="calculator">
            <!-- form the display to match the keypad -->
            <table border="1" cellpadding="1" bordercolor="#FFFFFF" bgcolor="#ababab" cellspacing="1" width="200">
            <tr>
            <td>
            <input type="text" size="25" length="25" value="" name="ans" style="background:beige;color:black;">
            </td>
            </tr>
            </table>
            <!-- form the keypad with buttons in a table -->
            <table border="1" cellpadding="1" bordercolor="#FFFFFF" cellspacing="1" width="200" bgcolor="#ababab">
            <tr>
            <td align="center">
            <input type="button" value=" 7 " name="seven" onClick="document.calculator.ans.value+='7'">
            </td>
            <td align="center">
            <input type="button" value=" 8 " name="eight" onClick="document.calculator.ans.value+='8'">
            </td>
            <td align="center">
            <input type="button" value=" 9 " name="nine" onClick="document.calculator.ans.value+='9'">
            </td>
            <td align="center">
            <input type="button" value=" / " name="divide" onClick="document.calculator.ans.value+='/'">
            </td>
            </tr>
            <tr>
            <td align="center">
            <input type="button" value=" 4 " name="four" onClick="document.calculator.ans.value+='4'">
            </td>
            <td align="center">
            <input type="button" value=" 5 " name="five" onClick="document.calculator.ans.value+='5'">
            </td>
            <td align="center">
            <input type="button" value=" 6 " name="six" onClick="document.calculator.ans.value+='6'">
            </td>
            <td align="center">
            <input type="button" value=" * " name="multiply" onClick="document.calculator.ans.value+='*'">
            </td>
            </tr>
            <tr>
            <td align="center">
            <input type="button" value=" 1 " name="one" onClick="document.calculator.ans.value+='1'">
            </td>
            <td align="center">
            <input type="button" value=" 2 " name="two" onClick="document.calculator.ans.value+='2'">
            </td>
            <td align="center">
            <input type="button" value=" 3 " name="three" onClick="document.calculator.ans.value+='3'">
            </td>
            <td align="center">
            <input type="button" value=" - " name="subtract" onClick="document.calculator.ans.value+='-'">
            </td>
            </tr>
            <tr>
            <td align="center">
            <input type="button" value=" C " name="clear" onClick="document.calculator.ans.value=''">
            </td>
            <td align="center">
            <input type="button" value=" 0 " name="zero" onClick="document.calculator.ans.value+='0'">
            </td>
            <td align="center">
            <input type="button" value=" = " name="equal"
            onClick="document.calculator.ans.value=eval(docume nt.calculator.ans.value)">
            </td>
            <td align="center">
            <input type="button" value=" + " name="add" onClick="document.calculator.ans.value+='+'">
            </td>
            </tr>
            </table>
            </form>
            </body>
            </html>
            Regards Chris.

            Collectables, Collecting, collectors-info.com

            www.chrismorris.co.uk

            House build project

            Comment

            • judavvforum
              Major

              • Nov 2007
              • 384

              #7
              Re: how to add a simple calculation

              Thanks Chris..
              Just tried it out and there is a small error:
              onClick="document.calculator.ans.value=
              eval(docume nt.calculator.ans.value)"> (Had to split this code so it didn't do a line break right where the error is!! Notice the space in the word document)

              Comment

              • CarbonTerry
                Major General

                • Oct 2005
                • 2620

                #8
                Re: how to add a simple calculation

                I don't know where that " symbol " came from in the 8 line.
                It's not in the original code.
                CarbonTerry
                Semper Fi
                Still green...still mean......just not as lean

                Red Hawk Archery
                Zone 5 Photo
                My USMC

                Comment

                • Collectors-info
                  General

                  • Feb 2006
                  • 8703

                  #9
                  Re: how to add a simple calculation

                  Ah! well done. think it may of been me pasting it into the quote box as well that didnt help.

                  Good luck.
                  Regards Chris.

                  Collectables, Collecting, collectors-info.com

                  www.chrismorris.co.uk

                  House build project

                  Comment

                  • CarbonTerry
                    Major General

                    • Oct 2005
                    • 2620

                    #10
                    Re: how to add a simple calculation

                    Chris,
                    The submitted code for the simple calculator would not total for me ??
                    The strange symbol for my code was indeed in my original posting but not in the original code from my files.
                    CarbonTerry
                    Semper Fi
                    Still green...still mean......just not as lean

                    Red Hawk Archery
                    Zone 5 Photo
                    My USMC

                    Comment

                    • judavvforum
                      Major

                      • Nov 2007
                      • 384

                      #11
                      Re: how to add a simple calculation

                      All's well and good fellows. The errors are easily changed and do work! Just wanted to make it known to everyone that might use them.

                      Comment

                      • navaldesign
                        General & Forum Moderator

                        • Oct 2005
                        • 12080

                        #12
                        Re: how to add a simple calculation

                        I understand the need for a calculator where it is in fact needed. But for a simple addition ?

                        Usualy these functions are part of order forms, or similar, where simplicity and functionality are a MUST, so a simple real time javascript would be much better.
                        Navaldesign
                        Logger Lite: Low Cost, Customizable, multifeatured Login script
                        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                        Comment

                        Working...
                        X