I am developing POS application, I am retrieving product after searching the barcode (which is saved in database in product table), there is add Cart button on which I click will add the product details,price and quantity in order table in database and will show after adding to database, if I enter the same product then its price and quantity should be increased.
when I click on add cart for the same product it's retrieving the records from Database with updated quantity and price but it's adding new row instead of updating existing row (because of append) is there any other way which I can create a table so that each time I don't have to append a new row.
$(document).ready(function(){
$("#submit").click(function(event){
var barcode=$(this).closest("tr").find("td:nth-child(1)").text();
var product=$(this).closest("tr").find("td:nth-child(2)").text();
var price=$(this).closest("tr").find("td:nth-child(3)").text();
var order={"barcodeid":barcode,"pname":product,"price":price,"qty":1}
console.log(orderid);
$.ajax({
type:'POST',
url:'/pos/addproduct',
dataType: "json",
data:JSON.stringify(order),
contentType: "application/json; charset=utf-8",
success:
function(data){
$.each(data,function(index,value){
var row=$("<tr><td>"+value.oid+"</td>"+"<td>"+value.pname+"</td>"+
"<td>"+value.qty+"</td>"+"<td>"+value.price+"</td>"+"<td>"
+value.barcodeid+"</td></tr>");
$("#order").append(row).removeClass("hidden");
})
}
})
});
})
and the order table is
<table id="order" class="hidden" align="center">
<tr>
<th>OrderId</th>
<th>ProductName</th>
<th>Quantity</th>
<th>Price</th>
<th>Barcode</th>
</tr>
<tr >
</table>
