<script> function sum(){ var a = +document.getElementById('oprd1').value, b = +document.getElementById('oprd2').value; document.getElementById('sum').innerHTML = a+b; }; </script> <input id="oprd1" type="text" onchange="sum();"> + <input id="oprd2" type="text" onchange="sum();"> = <span id="sum"></span>