I am currently working on a listing page that displays item name, price, and quantity. My goal is to implement a feature where if a user increases the quantity of an item from the list, the price will also change accordingly. Below is a snippet from my file view_item.ctp:
<?php
foreach($result as $k=>$v) { ?>
<tr class="hide_me_<?php echo $v['Inventory']['id']; ?> ">
<td><i class="fa fa-chevron-right"></i></td>
<td><?php echo $v['Inventory']['item_name']; ?></td>
<td class="text-center">
<span class="box-plush" id='plusbutton' onclick="itemQty(<?php echo
$v['Inventory']['id']; ?>,'incr')"><i class="fa fa-plus"></i></span>
<span class="box-dgt" id='att_<?php echo $v['Inventory']['id']; ?
>'>1</span>
<span class="box-minus" id='minusbutton' onclick="itemQty(<?php echo
$v['Inventory']['id']; ?>,'decr')"><i class="fa fa-minus"></i> </span>
</td>
<td class="text-center" id='price_<?php echo $v['Inventory']['id']; ?>'><?
php echo $v['Inventory']['item_price']; ?></td>
<td class="text-right"><?php echo $v['Inventory']['item_price']; ?></td>
<td class="text-center">
<a class="btn btn-danger btn-sm close-box" href="javascript:void(0)"
onclick="menuItem(<?php echo $v['Inventory']['id']; ?>)">
<i class="fa fa-times" ></i>
</a>
</td>
</tr>
<?php } ?>
<script type="text/javascript">
function menuItem(id){
$('.hide_me_'+id).hide();
}
function itemQty(id,action){
var qty = $('#att_'+id).text();
qty = parseInt(qty);
if(action=="incr"){
$qty1 = qty+1;
}else{
$qty1 = qty-1;
}
$('#att_'+id).text($qty1);
}
</script>