jQuery discount on quantity

Asked

Viewed 99 times

-2

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 know how to do input multiplication and result. however I want to give discount to each 3 product. If the customer:

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)

1 answer

1

Simple, take the rest of the division by 3, if zero means you can give discount, then just take the total of products and divide by 3 to give the amount of products to be discounted.

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>


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.