Calculating with javascript -
ok have html , want calculate quantity * priceperitem numbers put in input . thx in advance.
book store
<h3>please select books</h3> <div> <label for="quantity">quantity</label> <input type="text" id="quantity" /> </div> <div> <label for="quantity">price per item</label> <input type="text" id="priceperitem" /> </div> <div> <button>view price</button> </div> <div class="payment-info"> amount pay: <span id="total"></span> </div> $(document).ready(function() { var quantity = $("#quantity"); var price = $("#priceperitem"); $("total").text(price * quantity); });`
$(document).ready(function() { $('button').on('click',function(){ var quantity = parsefloat($("#quantity").val()); var price = parsefloat($("#priceperitem").val()); $('#total').html(price * quantity); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <h3>please select books</h3> <div> <label for="quantity">quantity</label> <input type="text" id="quantity" /> </div> <div> <label for="quantity">price per item</label> <input type="text" id="priceperitem" /> </div> <div> <button>view price</button> </div> <div class="payment-info"> amount pay: <span id="total"></span> </div>
Comments
Post a Comment