I have 3 fields (a, b, c) that I need to add and play the value in field (d) as it is being typed, but I can not do it without clicking or typing something after the last number.
I tried to use the onkeyup
and onkeydown
Is there any way?
function id(el) {
return document.getElementById(el);
}
function calcular(el) {
var a = id('a').value;
var b = id('b').value;
var c = id('c').value;
id('d').value = parseInt(a) + parseInt(b) + parseInt(c);
}
<input type="text" id="a" name="a" onkeyup="calcular()" onkeydown="calcular()" />
<input type="text" id="b" name="b" onkeyup="calcular()" onkeydown="calcular()" />
<input type="text" id="c" name="c" onkeyup="calcular()" onkeydown="calcular()" />
<input type="text" id="d" name="d" disabled="disabled" />