$(document).ready(function() { $('.calc').on('input', function() { var t1 = document.getElementById('txt1'); var t2 = document.getElementById('txt2'); var tot=0; if (parseInt(t1.value)) tot += parseInt(t1.value); if (parseInt(t2.value)) tot += parseInt(t2.value); document.getElementById('txt3').value = tot; }); });