146
rated 0 times
[
147]
[
1]
/ answers: 1 / hits: 115967
/ 12 Years ago, thu, june 14, 2012, 12:00:00
I have a simple HTML form, with 3 input field, when you hit = button, it suppose to add 2 numbers that you typed in the first 2 input fields and display result in 3rd filed. Is it possible to do that? (I need result in a box (or table) or some thing rather than in plain text). I try the following but doesn't work (it does nothing), can somebody help me?
<HTML>
<HEAD>
<TITLE>Sum</TITLE>
<script type=text/javascript>
function sum()
{
var num1 = document.myform.number1.value;
var num2 = document.myform.number2.value;
var sum = parseInt(num1) + parseInt(num2);
document.getElementById('add').innerHTML = sum;
}
</script>
</HEAD>
<BODY>
<FORM NAME=myform>
<INPUT TYPE=text NAME=number1 VALUE=> +
<INPUT TYPE=text NAME=number2 VALUE=>
<INPUT TYPE=button NAME=button Value== onClick=sum()>
<INPUT TYPE=text ID=add NAME=result VALUE=>
</FORM>
</BODY>
</HTML>
More From » html