Help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed Blinn

    Help!

    Hello,

    I programmed this script, but I can't get the second function to work. It
    is the one that computes the square of a number. I can't get it to load into
    the iframe. Please let me know what I did wrong.

    Thanks,
    Ed

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script type="text/javascript">
    //Square Root
    function squareroot()
    {
    x=document.root
    data=x.num.valu e
    var sqr=Math.sqrt(d ata)
    parent.sqrt.doc ument.write(sqr )
    }
    //Squared of an item
    function squared()
    {
    x=document.squa re
    data=x.num.valu e
    var sum=data*data
    parent.squaredf rame.document.w rite()
    }
    //Tanget
    function tangent()
    {
    x=document.tang ent
    data=x.num.valu e
    var tan=Math.tan(da ta)
    parent.tangentf rame.document.w rite(tan)
    }
    //Refresh Values
    function refresh()
    {
    location.reload (sqrt)
    location.reload (squaredframe)
    location.reload (tangentframe)
    }
    </script>
    </head>

    <body>
    <table width="100%" border="1">
    <tr>
    <td width="73%" height="50">
    <form name="root">
    Type in a number to compute the square root of the value.
    <input name="num2" type="text" id="num" size="10" maxlength="10">
    <input name="button" type="button" onClick="square root()"
    value="Compute" >
    </form></td>
    <td width="27%" height="50"><if rame name="sqrt" width="100%" height="50"
    frameborder="0" scrolling="no"> </iframe></td>
    </tr>
    <tr>
    <td height="50">
    <form name="square">
    Type in a number to compute the square of the value.
    <input name="num3" type="text" id="num2" size="10" maxlength="10">
    <input name="button2" type="button" onClick="square d()"
    value="Compute" >
    </form></td>
    <td><iframe name="squaredfr ame" width="100%" height="50" frameborder="0"
    scrolling="no"> </iframe></td>
    </tr>
    <tr>
    <td height="50">
    <form name="tangent">
    Type in a number to compute the tanget of the value.
    <input name="num" type="text" id="num3" size="10" maxlength="10">
    <input name="button3" type="button" onClick="tangen t()"
    value="Compute" >
    </form></td>
    <td><iframe name="tangentfr ame" width="100%" height="50" frameborder="0"
    scrolling="no"> </iframe></td>
    </tr>
    </table>
    <div align="right">
    <form name="refresh">
    Hit refresh to compute new values.
    <input type="button" onClick="refres h()" value="Refresh Values">
    </form>
    </div>
    </body>
    </html>

  • The Plankmeister

    #2
    Re: Help!

    In your functions you aren't accessing the relevant value. You have:

    data=x.num.valu e

    in all the functions, but in your separate forms, the id attribute of each
    is different, so the script cannot get the correct value. If you give each
    of your text inputs a unique id. For example, respectively:

    id="sqrt_input "
    id="squared_inp ut"
    id="tan_input"

    You can then replace these lines in your functions:

    x=document.[whatever]
    data=x.num.valu e

    with this:

    data = document.getEle mentById("sqrt_ input").value

    Obviously you'll have to change the quoted value to reflect the real names
    you assign to your ID attributes for each of the functions.
    I haven't tested this, but at first glance that would definitely appear to
    be the issue. Also, I think your function tangent() is a reserved word. Try
    changing it to my_tangent() or something...

    HTH.

    P.


    Comment

    Working...