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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.