I can not figure out why only integers are added / minus
There is a small calculator with hidden input, in which there is a value value, when you press "+", "-", addition / subtraction should be in that number and decimal number. Now only integers are added.
https://jsfiddle.net/L08danx8/
<form action="#" method="get" name="form-kitchen"> <table cellpadding='0' cellspacing='0' class='modal-kitchen__calc'> <td> <input type='hidden' name='price' value='139.90'> </td> <td> <div class='calc__value'> <span class="value__text">Количество: </span> <input type='text' onkeyup="this.value=this.value.replace(/[^\d\.]+/g,'')" name='col' value='0' /> <a class='minus'>-</a> <a class='plus'>+</a> </div> </td> <td class="modal-kitchen__sum">руб.</td> </table> <input type="submit" class="form-kitchen__btn" value="Заказать"> </form> Js
var order={}; $('.minus').click(function () { var $input = $(this).parent().find('input'); var count = parseInt($input.val()) - 1.0; count = count < 0 ? 0 : count; $input.val(count); $input.change(); return false; }); $('.plus').click(function () { var $input = $(this).parent().find('input'); $input.val(parseInt($input.val()) + 1.0); $input.change(); return false; }); $('.modal-kitchen__calc').on('change','.calc__value input',calculate_price); function calculate_price() { var $input=$(this), count=$input.val(), price=parseFloat($input.parents('td').prev().children('input').val()), sum=parseInt(price*count), item=$input.parents('tr').children('tr').eq(2); $input.parents('td').next().text((print_price(sum))).data('sum',sum); if (count===0) { delete(order[num]); calc_sum(); return; } order[item]={sum: sum,count: count}; calc_sum(); } function calc_sum() { var sum=0; for (var key in order) { sum+=order[key].sum; } $('.modal-kitchen__calc').find('td').last().text(print_price(sum)); } function print_price(v) { return ((v*100)+'').replace(/(..)$/,',$1 руб.') }