doh85 Posted April 14, 2009 Share Posted April 14, 2009 <? $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 https://forums.phpfreaks.com/topic/154014-help-with-counting-entries-in-input-fields/ Share on other sites More sharing options...
Daniel0 Posted April 14, 2009 Share Posted April 14, 2009 Assuming you're submitting through POST: $qty = array_sum($_POST['txtQty']); Link to comment https://forums.phpfreaks.com/topic/154014-help-with-counting-entries-in-input-fields/#findComment-809627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.