Code not working

Discussion in 'Javascript' started by Michael_jd, Oct 4, 2004.

  1. Michael_jd

    Michael_jd Guest

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

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

    <script language="javascript">

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

    alert(num_ein+num_zwei+num_drei);
    }

    </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.
     
    Michael_jd, Oct 4, 2004
    #1
    1. Advertisements

  2. Michael_jd

    Lee Guest

    Michael_jd said:
    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:

    http://www.jibbering.com/faq/#FAQ4_21
     
    Lee, Oct 4, 2004
    #2
    1. Advertisements

  3. Michael_jd

    Randy Webb Guest

    Rename the form or rename your function.
     
    Randy Webb, Oct 4, 2004
    #3
  4. In this particular instance, it's mandatory. Parentheses cannot appear in
    attribute values without quotation marks.

    [snip]

    Mike
     
    Michael Winter, Oct 4, 2004
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.