I have a submit button for input type = "number", when I change value of input tag, subtotal
will be change:
<form action="<?php echo base_url('cart/update') ?>" method="post">
<input type="number" name="qty_<?php echo $row['id'] ?>" value="<?php echo $row['qty']; ?>"/>
<button type="submit">Update</button>
Total: <?php echo number_format($row['subtotal']); ?>
</form>
In Cart
controller, this function update qty
and change value of $row['subtotal']
:
function update(){
$carts = $this->cart->contents();
foreach ($carts as $key => $row){
$total_qty = $this->input->post('qty_'.$row['id']);
$data = array();
$data['rowid'] = $key;
$data['qty'] = $total_qty;
$this->cart->update($data);
}
redirect(base_url('cart'));
}
Then, I want to use a onchange event, but I dont have idea. How to call update function? I try this:
<input type="number" name="qty_<?php echo $row['id'] ?>" value="<?php echo $row['qty']; ?>" onchange=<?php echo base_url('cart/update')?>/>
Of course, it doesn't work.
Please help. Thanks.