javascript - change the subtotal dynamically when the quantity changes in shopping cart -
i want javascript code achieve simple thing. subtotal price should changed according quantity user changes. if price 1000 , quantity changed 2 subtotal should 2000.
here code :
<input type="number" min="0" class="form-control" id="quantity" value="1"> </td> <td> <input type="text" class="form-control" id="price" value="1000" readonly> </td> <td> <input type="text" class="form-control" id="subtotal" value="1000"> </td>
i'm 0 in javascript. please show me way add script inside html.
$(document).ready(function(){ $("#quantity").change(function(){ $("#subtotal").val(parseint($(this).val()) * parseint($("#price").val())); }); });
i have added plunker - http://plnkr.co/edit/af6g1ssjztlreh6cbbul
firstly, add code in document ready block executes code after document ready. secondly, bind onchange event input field id quantity , calculations. please note, should validations, if word entered or filed left blank, etc.
Comments
Post a Comment