how do i calculate 2 input fields and put results in 3rd input field

强颜欢笑 提交于 2019-12-06 06:37:15

Though you got the answer but you should type cast the values you type in inputs. I mean what if someone type any other value other than integer... then you will get NaN in 3rd textbox..Here is solution to handle this problem

$(document).ready(function(){
    var qty=$("#qty");
    qty.keyup(function(){
        var total=isNaN(parseInt(qty.val()* $("#price").val())) ? 0 :(qty.val()* $("#price").val())
        $("#total").val(total);
    });
});

or you can check jsfiddle http://jsfiddle.net/ugPxf/

$("#qty").keyup(function(){
   total = $("#qty").val()* $("#price").val();
   $("#total").val(total);
});

This should work.

$('#qty').on('keyup',function(){
     $('#total').val( $('#qty').val() * $('#price').val());
});

R.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!