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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with calculation code

    Hi

    Can anyone please help me:

    I need to create a form where the visitor can enter a numeric value in a Form Field and then click on a "calculate button" where the entered value then are subtracted from 2004 and the result divided by 50. This result must then be returned as 4 values:
    1 --> the result "to the power of" 0.25
    2 --> the result "to the power of" 0.5
    3. --> the result "to the power of" 0.75
    4. --> the result "to the power of" 1.5

    For example if the value entered is 1864 then:
    2004 - 1864 / 50 = 2.80 (should be rounded to the neartest = 3)
    1. --> 3 to the power of 0.25
    2. --> 3 to the power of 0.50 etc

    Is there any way to do this?

    Thanx!

  • #2
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why do you want to do this?

    Yes, I think that it is possible.
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums

  • #3
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why do you want so man diferent "to the power" parts?

    If you tell me then I will help.
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Most everything you need is in the Math object
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #5
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,695
    Thanks
    0
    Thanked 232 Times in 227 Posts
    Hi there Deedee,

    Try this little offering...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <meta content="mshtml 6.00.2800.1264" name="generator" />
    <title>DeeDee calculations</title>
    <style type="text/css">
     /*<![CDATA[*/
    body{font-family:arial;font-size:16px;font-weight:bold;}
    div#one{position:absolute;top:50px;left:300px;padding:30px;border:double 6px #000000;background-color:#a0a0c0;}
    input{text-align:center;color:#000080;width:60px;margin:2px;}
    /*]]>*/
    </style>
    <script type="text/javascript">
    //<![CDATA[
    function show()
    {
    var number=document.getElementById("number").value;
    var x=Math.round((2004-number)/50);
    var one=Math.pow(x,1/4).toFixed(4);
    var two=Math.pow(x,1/2).toFixed(4);
    var three=Math.pow(x,3/4).toFixed(4);
    var four=Math.pow(x,3/2).toFixed(4);
    
    document.getElementById("resultone").value=one;
    document.getElementById("resulttwo").value=two;
    document.getElementById("resultthree").value=three;
    document.getElementById("resultfour").value=four;
    }
    //]]>
    </script>
    </head>
    <body>
    <div id="one">
    <form action="">
    <div>
    <input id="number" type="text"/>Number<br /><br />
    <input id="resultone" type="text"/>0.25<br /><br />
    <input id="resulttwo" type="text"/>0.5<br /><br />
    <input id="resultthree" type="text"/>0.75<br /><br />
    <input id="resultfour" type="text"/> 1.5<br /><br />
    <input id="button" type="button" value="Show" onclick="show();return false;" />&#160;
    <input type="reset" value="Reset" name="Reset"/>
    </div>
    </form>
    </div>
    </body>
    </html>
    cthead

  • #6
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nice code.
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums

  • #7
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Geeee thanx Coothead! It's exactly what I needed!!


  • #8
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,695
    Thanks
    0
    Thanked 232 Times in 227 Posts
    You are Welcome


  •  

    Posting Permissions

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