1 reply [Last post]
tqmd1
tqmd1's picture
Offline
Regular
Pakistan
Last seen: 44 weeks 5 days ago
Pakistan
Timezone: GMT+5
Joined: 2011-10-15
Posts: 15
Points: 31

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

//mod edit: wrong forum, moved to off topic ~gt

balajidesign
balajidesign's picture
Offline
Enthusiast
Last seen: 47 weeks 6 days ago
Timezone: GMT+5.5
Joined: 2012-01-31
Posts: 116
Points: 124

Hi, use this

Hi,

use this code:

<html>
<head>
<title>this is first math exercise within Java Script</title>
 
<script lanuage="Javascript">
function total()
{
var amount1 = calculate.text1.value
var amount2 = calculate.text2.value
 
var total=eval(amount1) + eval(amount2)
calculate.text3.value=total
alter("Correct Answer")
}
</script>
 
</head>
 
<body>
<center>
<form name="calculate">
<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>