Jump to content

Help With Counting Entries In Input Fields


doh85

Recommended Posts

<?
$ct_qty = 0;
$subTotal = 0;
for ($i = 0; $i < $numItem; $i++) {
extract($cartContent[$i]);
$productUrl = "index.php?c=$cat_id&p=$pd_id";
$subTotal += $pd_price * $ct_qty;
?>

<div class="cart-item">
<div class="item"><a href="<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>"><img src="images/remove.png" alt=""></a><a href="<?php echo $productUrl; ?>"><?php echo $pd_name; ?></a></div>
<div class="item-price"><?php echo displayAmount($pd_price); ?></div>
<div class="item-quantity">
  <input maxlength="3" name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);" />
  <input name="hidCartId[]" type="hidden" value="<?php echo $ct_id; ?>" />
  <input name="hidProductId[]" type="hidden" value="<?php echo $pd_id; ?>" />
</div>
<div class="item-total"><?php echo displayAmount($pd_price * $ct_qty); ?></div>
</div>

 

Basically this generates items in a shopping cart. I want to count all of the qtys in the input field and then add them together to have a overall number of items.

 

<input maxlength="3" name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);" />

 

This is the line of code that the qty is entered into.

 

How would i do this, im kinda a noob with php.

 

Any help is much appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.