How to determine the values of dynamically generated input type=number in the bin?

php code:
<?php foreach ($catalog as $catalogItem):?>
 <tr class="item_box">
 <td><h1><?php echo $catalogItem['name'];?></h1></td>
 <td><div class="item_price"><?php echo $catalogItem['price'];?></div></td>
 <td><input type=number id="kol" value="" ></td>
 <td><button class="add_item" data-id="<?php echo $catalogItem['id_product'];?>" data-title="<?php echo $catalogItem['name'];?>" data-price="<?php echo $catalogItem['price'];?>">add to order</button></td></tr> 
 <?php endforeach; ?>


a piece of js:
addToCart: function(e) {
e.preventDefault();
 itemData = $(this).data();
 if(typeof itemData.id === 'undefined') {
 console.log('Missing item ID');
 return false;
}
 cartData = actions.getStorage() || {};
 if (cartData.hasOwnProperty(itemData.id)) {
 cartData[itemData.id].count = parseInt(cartData[itemData.id].count)+parseInt($('#Col').val());
 } else {
 itemData.count = $('#Col').val(); 
 cartData[itemData.id] = itemData;
}
actions.setStorage(cartData);
actions.changeTotalCnt(1);
label.show();
 if(opts.openByAdding) {
actions.openCart();
}
 return false;
 }

The first product is added to and changed the number as expected, but the following go with the number from the first input to have the same id. If the record id to a variable
id=""whereas to obtain the value for each item ?
I would be grateful if someone can guide on the right path .
March 19th 20 at 08:23
1 answer
March 19th 20 at 08:25
Solution
$(`#${itemData.id}`).val()

Find more questions by tags JavaScript