Hi all, I have a small problem in a shopping cart for an ecommerce site. I have a function in the shopping cart that add one unit if I make add to cart, and to do an update of this quantity I have a list menu with only 20 numbers from where I can select the quantity. Does anyone knows whow can I, instead of list menu with 20 numbers, place a text field where the user insert the quantity? Thanks. António This is the code: <?php $id=$row['itemId'];?> <? //print "<input type=\"text\" name=\"qty'.$id.'\" value='.$qtd.' size=\"3\" maxlength=\"3\" onChange='UpdateQty(this)'/>" ?> <select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)"> <?php for($i = 1; $i <= 20; $i++) { echo "<option "; if($row["qty"] == $i) { echo " SELECTED "; } echo ">" . $i . "</option>"; } ?> </select>
<?php $id=$row['itemId'];?> <? //print "<input type=\"text\" name=\"qty'.$id.'\" value='.$qtd.' size=\"3\" maxlength=\"3\" onChange='UpdateQty(this)'/>" ?> <input type="text" name="<?php echo $row["itemId"]; ?>" value="<?php echo $row["qty"]; ?>" onChange="UpdateQty(this)"> PHP: You will need to do some validation & sanitisation of the input to this field though.......
Thanks for your fast reply. I did the changes but in doesn´t update! I think that I need to change my function UpdateQty, but I don’t know where… Sorry for my low knowledge of PHP… Can you help? António <script language="JavaScript"> <!-- function UpdateQty(item) { itemId = item.name; newQty = item.options[item.selectedIndex].text; document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty; } //--> </script>