When the user selects an item, I save the id
item to hidden input
in the panel. Now, when the user selects the same item, I want to check if id
the panel exists , and if that happens, I will change the quantity value from 1 to 2.
How can i achieve this?
PS: When using the code below, when the user selects an existing item in the panel, he adds the item again, and I have duplicates.
function findID(sol)
{
var products = JSON.parse(sol.dataset.sol);
if(sol.checked == true) {
$('.panel').append(
'<div class="container" style=" font-size:14px; "> '+
'<input type="hidden" value='+products.id+' data-id="'+products.id+'" name="food_id[]" />'+
'<table style="width:100%;" class="table" id="tables">'+
'<tbody id="item_list">'+
'<tr>'+
'<td class="name" >'+products.name+'</td>'+
'<td><input size="50" type="text" value="1" class="form-control quantity" id="qty" placeholder=" qty " name="quantity[]" required/></td>'+
'</tr>'+
'</tbody>'+
'</table>'+
'</div>'
)
}
}
source
share