With an increase in the amount, the amount should increase, but at colivevism 10, if pressed down, the amount displays 300, but should output 100. How can I fix this?

$("#kol").change(function() { nV = $(this).val(); oV = this.name; this.name = nV; p = $(this).parent().parent(); kol = $("#kol").val(); showsum = $("#sum").val(); sum = $("#realsum").val(); if(nV > oV) { mul = parseInt(sum) + parseInt(showsum); } else { mul = parseInt(showsum) - parseInt(sum); } res = p.find("#sum"); res.html(mul); total = 0; $("#sum").val(mul); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"> </script> Количевство: <input type="number" id="kol" min="5" value="5" step="5"><br><br> Сумма: <input type="hidden" id="realsum" value="100"> <input type="text" id="sum" min="100" value="100"> руб 

  • Some kind of incomprehensible salad. Количество is count of bills? Why not just count the number by 100? - Mr. Black
  • 5 pieces worth 100 rubles. 10 pieces worth 200 rubles. itd coming - Sauron
  • Should the sum be exactly input or can it just be text output? - Mr. Black
  • If I multiply the quantity by 100. Think about yourself 1000pcs worth 50rubles.2,000shares worth 100rubles.1000 * 100? ... - Sauron
  • You can simply text. - Sauron

1 answer 1

 $('#num').change(function() { $('#sum').text(this.value * this.name / this.min); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script> Количество <input id='num' type='number' value='10' min='10' step='10' name='100'> <br> Сумма: <span id='sum'>100</span> 

  • To be honest, with great difficulty I understand what is needed. Is this option appropriate? - Mr. Black
  • I changed <input id='num' type='number' value='10' min='10' step='10'> With an increase of 20 %, I received 400 руб . 20штук worth 200рублей - Sauron
  • @Sauron, until the question is correctly formulated, I cannot answer. If at 10pcs you need 100, and at 20 - 200, what is the problem to multiply by 10, instead of 20? - Mr. Black
  • @Sauron, updated the answer, maybe now what you need? The name indicates the minimum value of the sum, and in min minimum value of the amount. At {5pcs = 100r, 10pcs = 200r}, At {15pcs = 100r, 30pcs = 200r} - Mr. Black
  • Yes, now everything is exactly right. I wanted to get it). Thanks again - Sauron