table1 has contents ( items ) while table 2 has nothing ( because it is the shopping cart ) now what i want to do is to check if the user is adding the same item on the shopping cart and if he/she does it will add the qty and doesn’t write another tr. How can i do this?
#table 1
<table>
<tr><td>Item001</td><td>5.00</td></tr>
<tr><td>Item002</td><td>5.00</td></tr>
</table>
#table 2 //it is blank because it will be filled later via onclick from table1
<table>
</table>
if the user clicked item001 it will be appended to table2 now if the user selects item001 again it must not write item001 again on table2 but will only append the quantity.
UPDATE
var itemDesc = $(this).find('.desc').text();
var getPrice = $(this).find('.price').text();
var itemName = $(this).find('.itemName').text();
var currentId = $('#cartGrid tr').attr('id');
if(itemName == currentId)
{
qty +=1;
$('.tableQty').html(qty);
qty = 1;
}
else{
$('#cartGrid').append("<tr id="+ itemName +"><td>" + itemDesc + "</td><td class='tableQty'>"+ qty +"</td><td class='tablePrice'> $" + getPrice +"</td></tr>");
}
Now i got it to work. But only on the first item. Help? THank you
I modified your code a bit to get it working:
demo: http://jsfiddle.net/qmVHr/
// HTML
// JS
You didn’t post the complete code, but it seems like your problem is in this part: