javascript - How to update input value without clicking on input field? -
so have problem input value updated when clicked on input field ("total" input field, below "suma" ("kiekis" * "kaina" = "suma") column , readonly), want automatically update "totals" field (which @ bottom near "bendra suma").
js code:
$(document).on('keyup change', '.quantity, .price', function() { var row = $(this).closest('tr').get(0); var rowprice = $(row).find('.price').val(); var rowquantity = $(row).find('.quantity').val(); $(row).find('.total').val((rowprice * rowquantity).tofixed(2)); $('.total').blur(function () { var sum = 0; $('.total').each(function() { sum += parsefloat($(this).val()); }); $('#totals').val((sum).tofixed(2)); }); });
you can test how works in jsfiddle:
https://jsfiddle.net/xqy6qafk/
thanks in advance help!
you don't need put code in blur event handler...
put in keyup/change event handler section...
remove 8th line
$(document).on('keyup', '.quantity, .price', function() {
and second last line...
});
so have looks this...
$(document).on('keyup change', '.quantity, .price', function() { var row = $(this).closest('tr').get(0); var rowprice = $(row).find('.price').val(); var rowquantity = $(row).find('.quantity').val(); $(row).find('.total').val((rowprice * rowquantity).tofixed(2)); var sum = 0; $('.total').each(function() { sum += parsefloat($(this).val()) || 0; // if string entered, use 0 instead. }); $('#totals').val((sum).tofixed(2)); });
Comments
Post a Comment