You're looking for:
function add() {
var a = parseInt(document.calc.first.value, 10);
var b = parseInt(document.calc.second.value, 10);
var c = a + b;
document.calc.result.value = c;
}
You have to re-read a
and b
values each time they're changed.
Note 1: Also, remember about radix
parameter in parseInt(val, radix)
. It's 10
in your case (as I suppose). See this MDN article on why that's important.
Note 2: no need to call parseInt(c)
, because c
is already of the type number
.