Code not working

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

    Code not working

    Some code I wrote is not working. Here it is:

    <html>
    <head>
    <title>ex 5</title>

    <script language="javas cript">

    function Average()
    {
    num_ein=window. document.Averag e.num1.value;
    num_zwei=window .document.Avera ge.num2.value;
    num_drei=window .document.Avera ge.num3.value;

    alert(num_ein+n um_zwei+num_dre i);
    }

    </script>

    </head>

    <body>

    <form name="Average">
    <input type="text" name="num1"><br >
    <input type="text" name="num2"><br >
    <input type="text" name="num3"><br >
    <input type="button" name="button1" value="Click for
    Average" onClick=Average ()>
    </form>

    </body>
    </html>

    Internet Explorer says that the button object does not support the property or
    method. Please help.
  • Randy Webb

    #2
    Re: Code not working

    Michael_jd wrote:[color=blue]
    > Some code I wrote is not working. Here it is:[/color]

    <--snip-->
    [color=blue]
    > function Average()[/color]

    <--snip-->
    [color=blue]
    > <form name="Average">[/color]

    <--snip-->
    [color=blue]
    > Internet Explorer says that the button object does not support the property or
    > method. Please help.[/color]

    Rename the form or rename your function.

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • Lee

      #3
      Re: Code not working

      Michael_jd said:[color=blue]
      >
      >Some code I wrote is not working. Here it is:
      >
      ><html>
      ><head>
      ><title>ex 5</title>
      >
      ><script language="javas cript">
      >
      >function Average()
      >{
      > num_ein=window. document.Averag e.num1.value;
      > num_zwei=window .document.Avera ge.num2.value;
      > num_drei=window .document.Avera ge.num3.value;
      >
      > alert(num_ein+n um_zwei+num_dre i);
      >}
      >
      ></script>
      >
      ></head>
      >
      ><body>
      >
      ><form name="Average">
      ><input type="text" name="num1"><br >
      ><input type="text" name="num2"><br >
      ><input type="text" name="num3"><br >
      ><input type="button" name="button1" value="Click for
      >Average" onClick=Average ()>
      ></form>
      >
      ></body>
      ></html>
      >
      >Internet Explorer says that the button object does not support the property or
      >method. Please help.[/color]

      1. Don't give a form and a function the same name. They share name space.
      2. It's good practice to quote the value of the HTML onclick attribute.
      3. The "language" attribute of the <script> tag is deprecated.
      It's better to use: <script type="text/javascript">
      4. Once you get to the point that your function is working, you'll find
      that your alert is displaying the three string values concatinated,
      rather than converted to numbers and summed. This link should help
      you with that problem:



      Comment

      • Michael Winter

        #4
        Re: Code not working

        On 3 Oct 2004 17:10:12 -0700, Lee <REM0VElbspamtr ap@cox.net> wrote:
        [color=blue]
        > Michael_jd said:[/color]

        [snip]
        [color=blue][color=green]
        >> <input type="button" name="button1" value="Click for Average"
        >> onClick=Average ()>[/color][/color]

        [snip]
        [color=blue]
        > 2. It's good practice to quote the value of the HTML onclick attribute.[/color]

        In this particular instance, it's mandatory. Parentheses cannot appear in
        attribute values without quotation marks.

        [snip]

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        Working...