Hamza Shah

Hamza Shah

  • NA
  • 87
  • 21.4k

When increase in quantity results increase in price

Oct 20 2020 5:40 AM
In table i have product and it's quantity and price. I'm using plus and minus input button to increase or decrease the quantity of the product. I want increase and decrease in price according to the quantity. Can anyone help me Thanks in advance?
 
Here's my view Code
  1. <thead>  
  2. <tr>  
  3. <th scope="col">Company</th>  
  4. <th scope="col">Product</th>  
  5. <th width="200px">Quantity</th>  
  6. <th scope="col">Price</th>  
  7. </tr>  
  8. </thead>  
  9. <tbody>  
  10. <tr>  
  11. <td id="Company"></td>  
  12. <td id="Product"></td>  
  13. <td>  
  14. <div class="input-group">  
  15. <span class="input-group-btn"><button class="btn btn-default value-control" data- action="minus" data-target="font-size"><span class="glyphicon glyphicon-minus">  
  16. </span></button></span>  
  17. <input type="text" value="1" class="form-control" id="font-size">  
  18. <span class="input-group-btn"><button class="btn btn-default value-control" data-action="plus" data-target="font-size"><span class="glyphicon glyphicon-plus"></span></button></span>  
  19. </div>  
  20. </td>  
  21. <td id="Price"></td>  
  22. </tr>  
  23. </tbody>  
  24. <script>  
  25. $('#productSelect').change(function () {  
  26. var id = $(this).val();  
  27. if (id > 0) {  
  28. $.get("GetProduct", { productId: id }, function (result) {  
  29. console.log(result)  
  30. $("#Company").text(result.CompanyName);  
  31. $("#Product").text(result.ProductName);  
  32. $("#Quantity").text(result.ProductQuantity);  
  33. $("#Price").text(result.ProductPrice);  
  34. });  
  35. }  
  36. })  
  37. </script>
And Here is my Button's javascript Code
  1. <script>  
  2. $(document).on('click''.value-control'function () {  
  3. var action = $(this).attr('data-action')  
  4. var target = $(this).attr('data-target')  
  5. var value = parseFloat($('[id="' + target + '"]').val());  
  6. if (action == "plus") {  
  7. value++;  
  8. }  
  9. if (action == "minus") {  
  10. value--;  
  11. }  
  12. $('[id="' + target + '"]').val(value)  
  13. })  
  14. </script>

Answers (2)