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
- <thead>
- <tr>
- <th scope="col">Company</th>
- <th scope="col">Product</th>
- <th width="200px">Quantity</th>
- <th scope="col">Price</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td id="Company"></td>
- <td id="Product"></td>
- <td>
- <div class="input-group">
- <span class="input-group-btn"><button class="btn btn-default value-control" data- action="minus" data-target="font-size"><span class="glyphicon glyphicon-minus">
- </span></button></span>
- <input type="text" value="1" class="form-control" id="font-size">
- <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>
- </div>
- </td>
- <td id="Price"></td>
- </tr>
- </tbody>
- <script>
- $('#productSelect').change(function () {
- var id = $(this).val();
- if (id > 0) {
- $.get("GetProduct", { productId: id }, function (result) {
- console.log(result)
- $("#Company").text(result.CompanyName);
- $("#Product").text(result.ProductName);
- $("#Quantity").text(result.ProductQuantity);
- $("#Price").text(result.ProductPrice);
- });
- }
- })
- </script>
And Here is my Button's javascript Code
- <script>
- $(document).on('click', '.value-control', function () {
- var action = $(this).attr('data-action')
- var target = $(this).attr('data-target')
- var value = parseFloat($('[id="' + target + '"]').val());
- if (action == "plus") {
- value++;
- }
- if (action == "minus") {
- value--;
- }
- $('[id="' + target + '"]').val(value)
- })
- </script>