[help] Javascript Help

I have soem code im working on for wchool and I need some help... Can someone please help? I programmed the code my self... So if the code is pretty bad... blame me.

Here's my code:

<html>

<head><title>Add that crap</title>
<script language=JavaScript>

// <!----Java---->
function do_operation(){
var num1=document.form1.num1.value;
var num2=document.form1.num2.value;
document.form1.sum.value=1*num1+1*num2;
document.form1.diff.value=1*num1-1*num2;
document.form1.prod.value=1*num1*1*num2;
document.form1.quad.value=(1*num1)/(1*num2)
}
</script>
</HEAD>
<body>  
 <form name="form1">
  <b>Number1: </b><input type="text" name="num1" value=0><br>
  <b>Number2: </b><input type="text" name="num2" value=0><br>
   <input TYPE="Button" Name="button" Value="Its math time" onlick=do_operation()><hr>
  <b>Sum: </b> <input type="text" name="sum" value=0>
  <b>Diff: </b> <input type="text" name="diff" value=0>
  <b>Prod: </b> <input type="text" name="prod" value=0>
  <b>Quad: </b> <input type="text" name="quad" value=0>



</form> </body>
</html>

Help would really be appreciated... Thanx

#143666

The first problem I can see is your use of parentheses (or lack thereof)...

For example, you say:

 document.form1.sum.value=1*num1+1*num2;

Imagine num1 = 5 and num2 = 6.

This line of code would do the following:

1 * num1 = 1*num1 = 5

1 * num1 + 1 = 5 (from above) + 1 = 6

1*num1+1*num2 = 6 (from above) * 6 = 36

In other words, your code should read:

 document.form1.sum.value=(1*num1)+(1*num2);

Apply the same rules for the other lines of javascript - remember computers are stupid - they just execute each instruction as the come across it.

Other than that, the basics look, at first glance, to be fine...

I would, however, recommend tidying up your HTML and getting it all XHTMLified.

#143853

thanx stevie... I also fixed the event "onlick" to "onclick". And it worked fomr there.... just fixed it today.. I will make those modifications now while im at school.

edit: code updated... click there ---> http://ulhomepage.lps.org/133866/pages/asn17.html if you wanna see...

#143904