I have four input fields in my form Quantity, Rate, Amount GST. I want to calculate the GST amount after calculating the total amount.
My HTML FORM:
<div class="col-md-6"> <div class="form-group"> <label for="inputWebSite">Quantity :</label> <input type="text" name="quantity" id="quantity" onkeyup="calc()" placeholder="Enter Check in Time" value="" class="form-control" autocomplete="off"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="inputWebSite">Rate:</label> <input type="text" name="rate" id="rate" onkeyup="calc()" placeholder="Enter your Rate" value="" class="form-control" autocomplete="off"> </div> </div> <div class="col-md-6" id="amount_div"> <div class="form-group"> <label for="inputWebSite">Amount:</label> <input type="text" name="amount" id="amount" placeholder="Your Amount" value="" class="form-control" autocomplete="off"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="inputWebSite">GST:</label> <input type="text" name="gst" id="gst" onkeyup="calc()" placeholder="Enter GST" value="" class="form-control" autocomplete="off"> </div> </div> <div class="col-md-6" id="total_amount_div"> <div class="form-group"> <label for="inputWebSite">Total Amount:</label> <input type="text" name="total_amount" id="total_amount" placeholder="Your Total Amount" value="" class="form-control" autocomplete="off"> </div> </div>
First, do quantity and rate multiplication. after entering the quantity and rate that shows the amount, and then enter GST after entering GST that shows the total amount.
<script> function calc() { var textValue1 = document.getElementById('quantity').value==""?0:document.getElementById('quantity').value; var textValue2 = document.getElementById('rate').value==""?0:document.getElementById('rate').value; var gst = document.getElementById('gst').value; document.getElementById('amount').value = textValue1 * textValue2; var total_amount = document.getElementById('amount').value = textValue1 * textValue2; if(gst == "") { gst = 0; } var gst_persentage = (total_amount * gst) / 100; var percentage = document.getElementById('total_amount').value = parseFloat(total_amount) + parseFloat(gst_persentage); } </script>
Question and answer is powered by AnsPress.io