#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    2
    Rep Power
    0

    Javascript equation


    I'd like to run the following equation in Javascript;

    (L*((r^2*(ACOS((r-h)/r)))-(SQRT(2*(r*h)-h^2)*(r-h))))/231

    Where the variables L, r, and h are input by the user.

    Thanks in advance for any help.
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    JavaScript has a built-in Math object with the methods you need (acos(), sqrt(), pow()).
    Code:
    <html>
    <head>
    <title>F'ugly Equation</title>
    <script language="javascript">
    function calculate(L, r, h)
      {
      return (L*((Math.pow(r,2)*(Math.acos((r-h)/r)))-(Math.sqrt(2*(r*h)-Math.pow(h,2))*(r-h))))/231;
      }
    </script>
    </head>
    <body>
    <form name="myForm">
    L: <input type="text" name="L"><br>
    r: <input type="text" name="r"><br>
    h: <input type="text" name="h"><br>
    <input type="button" value="Calculate" 
    onclick="javascript:document.myForm.result.value=calculate(document.myForm.L.value, document.myForm.r.value, document.myForm.h.value);"><br>
    Result: <input type="text" name="result">
    </form>
    </body>
    </html>
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    2
    Rep Power
    0
    Outstanding!

IMN logo majestic logo threadwatch logo seochat tools logo