jQuery quantity discount

1

I have two input one with value and the other with quantity and span for result

<input type="text" value="50,00">
<input type="number" value="3">
<span id="resultado"></span>

I need the following I can do the multiplication of the input and the result. but I want to give every 3 product a discount. If the client:

1) digitar 3 dou desconto de 1.
2) digitar 5 dou ainda dou desconto de 1.
3) digitar 6 dou desconto de 2. (entre na regra de acada 3 produtos vc ganha 1)
4) digitar 9 dou desconto de 3. (por causa da regra)
5) digitar 10 dou desconto de 3. (por causa da regra)
    
asked by anonymous 26.03.2016 / 00:57

1 answer

1

Simple, get the rest of the division by 3, if it is zero means you can give a discount, then just get the total of products and divide by 3 to give the amount of products to have a discount.

Example:

$("input[type=number]").change(function() {
  if (this.value % 3 === 0) {
    $("#resultado").html("<br><br>Produtos a dar desconto: " + this.value / 3);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><inputtype="text" value="50,00">
<input type="number" value="3">
<span id="resultado"></span>
    
26.03.2016 / 01:30