Code not working

M

Michael_jd

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.
 
L

Lee

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

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
 
M

Michael Winter

Michael_jd said:
[snip]
<input type="button" name="button1" value="Click for Average"
onClick=Average()>
[snip]

2. It's good practice to quote the value of the HTML onclick attribute.

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

[snip]

Mike
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top