 <p>Above solution gives NaN if any text box is empty. please try this it will give 0. </p> <p>var v1=0; var v2=0;</p> <pre><code>if(!isNaN(parseInt($('input[name=amounty]').val()))){ v1 = parseInt($('input[name=amounty]').val()); } if(!isNaN(parseInt($('input[name=quatity]').val()))){ v2 = parseInt($('input[name=quatity]').val()); } sum = v1 * v2; </code></pre>