0

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

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by stbuchok
0

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

Post moved

0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.