Dear Experts

I have following codes

<html>
<head>
<title>this is first math exercise within Java Script</title>

<script lanuage="Javascript">
function total()
{
Var amount1 = text1.value
Var amount2 = text2.value
Var total=eval(amount1) + eval(amount2)
text3.value=total
alter("Correct Answer")
}
</script>

</head>

<body>
<center>
<form>
<table width="20%" border="1" cellpadding="1" cellspacing="1" >

<tr>
<td width="10%" align="center">Amount1</td>
<td width="10%"><input type="number" name="text1" value="" min="1001" max="8000"></td>
</tr>



<tr>
<td width="10%" align="center">Amount2</td>
<td width="10%"><input type="number" name="text2" value=""  min="1001" max="8000"></td>
</tr>

<tr>
<td width="10%" align="center">Total</td>
<td width="10%"><input type="number" name="text3" value=""  min="1001" max="8000""></td>
</tr>

<tr>
<td width="10%"></td>
<td width="10%"><INPUT TYPE="button" NAME="Submit" VALUE="Compute" onclick="total()">
<input type=reset Value="Clear" size="30"></td>
</tr>

</table>

</form>
</center>

</body>

</html>

I want to get summed value in text3 but function does not excecute.
What is wrong in my codes?

Please help

Dear tqmd1 either pay attention where you post or learn difference between JSP (Java Server Pages) where you posted this and JavaScript.

Post moved

Member Avatar for stbuchok

peter budo, this is in the right place, however he tagged his code as JSP, however it is JavaScript.

Var should be var
You are using eval wrong (it isn't needed for what you are doing)
Use document.getElementById, this also means give ids to your elements
End each line with ;
Put the starting { on the same line as the function declaration (there is good reason if you read up on javascript)
Give proper names to your for elements (text1, text2 and text3 are not descriptive)
Do proper indenting of the code for readability
In javascript if you want to turn a string into a number use parseFloat, however in your example it probably isn't needed.

That's all I care to comment on for now.

peter budo, this is in the right place, however he tagged his code as JSP, however it is JavaScript

Yes NOW it is in correct place, hence my comment Post moved

Member Avatar for stbuchok

;), gotcha

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.