1

I would like to count price and discount and quantity for result which is the total. Is it possible to do with javascript and how? I have tried several ways to implement the function in javascript however none of my effort works.



<body style="background-image: linear-gradient(to right, seagreen , lightyellow");>
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-3">
                <div class="card">
                    <div class="card-body">
                        <div class="form-group col-lg-12 col-md-12 col-sm-12">
                            <div>
                                <label>Customer Name:</label>
                                <input type="text" class="form-control" id="cname" name="customername" />
                            </div>
                                 <div>
                                    <label>Test Rate:</label>
                                    <input type="number" class="form-control calculationadd" id="testprice" name="testamt" />
                                </div>

                            <div>
                                <label>Quantity:</label>
                                <input type="number" class="form-control calculationadd" id="qty" name="qtyname" />
                            </div>

                            <div>
                                <label>Discount%:</label>
                                <input type="number" class="form-control calculationadd" id="discountid" name="dis" />
                            </div>

                            <div>
                                <label>Total:</label>
                                <input type="number" class="form-control calculationadd" id="totalid" name="total" />
                            </div>

                            <script>
                                $(".calculationadd").keyup(function () {
                                    var customername = $("#cname").val();
                                    var testamt = $("#testprice").val();
                                    var quan = $("#qty").val();
                                    var dis = $("#discountid").val();
                                    var total = $("#totalid").val();

                                    var rateqty = parseFloat(testamt) * parseFloat(quan);
                                    var afterdiscount = parseFloat(rateqty) * parseFloat(dis) / (100)
                                    var final = parseFloat(rateqty) - parseFloat(afterdiscount);

                                    $("#totalid").val(rateqty);
                                }
                                );
                            </script> 


                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</body>

j08691
  • 204,283
  • 31
  • 260
  • 272
tony
  • 11
  • 1
  • Can you explain the expected output? Your code works fine as you have written. – BadPiggie Aug 24 '22 at 07:17
  • You have to put $("#totalid").val(final); instead of $("#totalid").val(rateqty);., as if run you code its just calcualting the rate * quantity value and display in the total., you calculated the rate * quantity - discount in final ., but you didn't put in the total textbox. – Sund'er Aug 24 '22 at 07:40

0 Answers0