javascript - On the basis of quantity and product price, total price Update -


my html structure:

<div class="pricesection">         <label id="productprice">         <strong>         <span id="totalprice"> 129,00</span>         <span>$</span>         </strong>         </label>         <input type="text" value="1" name="am" id="quantity">         <button class="submitbtn" type="submit">add cart</button> </div> 

my js code:

$('#quantity').keyup(function(){   $('#quantity').each(function () {     var qty = $('#quantity').val();   var price = $('#totalprice').val();   var total = price * qty;   });    $('#totalprice').html(total); }); 

i have found many examples, not suitable. :-(

after entering quantity item price automatically updated. if "0", letter, "empty" or after canceling original price must restored.

i "0" value ​​back!

i grateful help!

try

var $totalprice = $('#totalprice'); var price = parseint($.trim($totalprice.text()).replace(',', '.')); $totalprice.data('totalprice', price); $('#quantity').keyup(function(){     var qty = this.value;     var price = $totalprice.data('totalprice');     var total = price * qty;      $totalprice.html(total ? total : price); }); 

note: number formatting not done


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -