There is a one section of orders page where users can add new fields to add new products. They choose a product from a drop down menu and its price is written in another column. I need to add a functionality that will allow users to enter quantity amount, and total price will be updated as soon as quantity amount changes. I tried it with the following codes but I keep receiving 0 for the total price.
My codes.
$('#AddProduct').click(function() {
var i = 0;
var adding = $(+(i++)+'<div class="row'+(i)+'"><div class="column width50"><input type="text" id="PRODUCTNAME" name="PRODUCTNAME'+(i)+'" value="" class="width98" /><input type="hidden" class="PRODUCTID" name="PRODUCTID" /><input type="hidden" class="UNITPRICE" name="UNITPRICE'+(i)+'" /><small>Search Products</small></div><div class="column width20"><input type="text" class="UNITQUANTITY" name="UNITQUANTITY'+(i)+'" value="" class="width98" /><small>Quantity</small></div><div class="column width30"><span class="prices">Unit Price:<span class="UNITPRICE"></span><br />Total Price:<span class="TOTALPRICE"></span><br /><a href="#" id="RemoveProduct(".row'+(i)+'");">Remove</a></span></div>');
$('#OrderProducts').append(adding);
adding.find("#PRODUCTNAME").autocomplete("orders.cs.asp?Process=ListProducts", {
selectFirst: false
}).result(function(event, data, formatted) {
if (data) {
adding.find(".UNITPRICE").html(data[1]);
adding.find(".PRODUCTID").val(data[2]);
adding.find(".TOTALPRICE").html(data[1] * $('.UNITQUANTITY').val());
}
});
return false;
});
<div id="OrderProducts">
<a href="#" id="AddProduct"><img src="icons/add.png" alt="Add" /></a>
</div>