javascript basic calculation price,quantity and discount

169 Views Asked by At

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>

0

There are 0 best solutions below