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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post [code] Need help on a html calculator please

    Hello I'm not very experienced in coding and was wondering if someone could assist me in making a simple calculator in html.

    Instead of just a simple calculator I need one that has a "insert value here" sort of thing. Here's the formula

    (Base Time) / (1 + 0.005 * ([[Knights|Foreman Politics Skill]]) + 0.1 * [[Research#Giant's Strength|Giant's Strength Research Level]])

    Basicly...

    .15 / (1 + 0.005 * _____ ) + 0.1 * _____ = _____

    (the ____ being places where the person inserts the numbers)

    Its for a game and i'm in the process of making a website, any assistance would be greatly appreciated.

  • #2
    Regular Coder
    Join Date
    Sep 2009
    Posts
    167
    Thanks
    15
    Thanked 1 Time in 1 Post
    you want to learn the basics of javascript. that will get you where you need to go.

  • #3
    New to the CF scene
    Join Date
    May 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Okay thats what ill do thank you very much

  • #4
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    There is much help here.

    Frank
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • Users who have thanked effpeetee for this post:

    Tyler James (05-14-2010)

  • #5
    New Coder
    Join Date
    May 2009
    Posts
    74
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Here i got something for you

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Calculator</title>
    </head>
    <style>
    input{ width:40px;}
    </style>
    <body>
    <form name="Keypad" action="">
    <table width="137" height="21" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="137">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    <table width="164" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td colspan="4"><input name="ReadOut" type="text" size="24" value="0" style="width:158px;" /></td>
    </tr>
    <tr>
    <td height="4" colspan="4"></td>
    </tr>
    <tr>
    <td><input name="btnClear" type="Button" value=" C " onclick="Clear()" /></td>
    <td><input name="btnClearEntry" type="Button" value=" CE " onclick="ClearEntry()" /></td>
    <td><input name="btnNeg" type="Button" value=" +/- " onclick="Neg()" /></td>
    <td><input name="btnDivide" type="Button" value=" / " onclick="Operation('/')" /></td>
    </tr>
    <tr>
    <td><input name="btnSeven" type="Button" value=" 7 " onclick="NumPressed(7)" /></td>
    <td><input name="btnEight" type="Button" value=" 8 " onclick="NumPressed(8)" /></td>
    <td><input name="btnNine" type="Button" value=" 9 " onclick="NumPressed(9)" /></td>
    <td><input name="btnPercent" type="Button" value=" % " onclick="Percent()" /></td>
    </tr>
    <tr>
    <td><input name="btnFour" type="Button" value=" 4 " onclick="NumPressed(4)" /></td>
    <td><input name="btnFive" type="Button" value=" 5 " onclick="NumPressed(5)" /></td>
    <td><input name="btnSix" type="Button" value=" 6 " onclick="NumPressed(6)" /></td>
    <td><input name="btnMultiply" type="Button" value=" * " onclick="Operation('*')" /></td>
    </tr>
    <tr>
    <td><input name="btnOne" type="button" value=" 1 " onclick="NumPressed(1)" /></td>
    <td><input name="btnTwo" type="button" value=" 2 " onclick="NumPressed(2)" /></td>
    <td><input name="btnThree" type="button" value=" 3 " onclick="NumPressed(3)" /></td>
    <td><input name="btnMinus" type="Button" value=" - " onclick="Operation('-')" /></td>
    </tr>
    <tr>
    <td><input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)" /></td>
    <td><input name="btnDecimal" type="Button" value=" . " onclick="Decimal()" /></td>
    <td><input name="btnEquals" type="Button" value=" = " onclick="Operation('=')" /></td>
    <td><input name="btnPlus" type="Button" value=" + " onclick="Operation('+')" /></td>
    </tr>
    </table>
    </form>
    <script>
    var FKeyPad = document.Keypad;
    var Accumulate = 0;
    var FlagNewNum = false;
    var PendingOp = "";
    function NumPressed (Num)
    {
    if (FlagNewNum) {
    FKeyPad.ReadOut.value = Num;
    FlagNewNum = false;
    }
    else
    {
    if (FKeyPad.ReadOut.value == "0")
    FKeyPad.ReadOut.value = Num;
    else
    FKeyPad.ReadOut.value += Num;
    }
    }
    function Operation (Op) {
    var Readout = FKeyPad.ReadOut.value;
    if (FlagNewNum && PendingOp != "=");
    else
    {
    FlagNewNum = true;
    if ( '+' == PendingOp )
    Accumulate += parseFloat(Readout);
    else if ( '-' == PendingOp )
    Accumulate -= parseFloat(Readout);
    else if ( '/' == PendingOp )
    Accumulate /= parseFloat(Readout);
    else if ( '*' == PendingOp )
    Accumulate *= parseFloat(Readout);
    else
    Accumulate = parseFloat(Readout);
    FKeyPad.ReadOut.value = Accumulate;
    PendingOp = Op;
    }
    }
    function Decimal () {
    var curReadOut = FKeyPad.ReadOut.value;
    if (FlagNewNum) {
    curReadOut = "0.";
    FlagNewNum = false;
    }
    else
    {
    if (curReadOut.indexOf(".") == -1)
    curReadOut += ".";
    }
    FKeyPad.ReadOut.value = curReadOut;
    }
    function ClearEntry () {
    FKeyPad.ReadOut.value = "0";
    FlagNewNum = true;
    }
    function Clear () {
    Accumulate = 0;
    PendingOp = "";
    ClearEntry();
    }
    function Neg () {
    FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
    }
    function Percent () {
    FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accumulate);
    }
    </script>
    </body>
    </html>

    Regards.

  • Users who have thanked frankle for this post:

    Tyler James (05-14-2010)

  • #6
    New to the CF scene
    Join Date
    May 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    doesn't seem to be working its just showing up as a normal calculator.

    Thanks anyways ill just learn the old fashion way .

  • #7
    New Coder
    Join Date
    May 2010
    Location
    Michigan, USA
    Posts
    56
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Runescape? And you can also use PHP, thats how I do my calculators. I find PHP to be easier than JavaScrip, thats just me though...


  •  

    Tags for this Thread

    Posting Permissions

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