Shopping cart for ecommerce site

Discussion in 'PHP' started by afonseca, Jun 1, 2006.

  1. #1
    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>
     
    afonseca, Jun 1, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?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.......
     
    mad4, Jun 1, 2006 IP
  3. afonseca

    afonseca Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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>
     
    afonseca, Jun 1, 2006 IP
  4. afonseca

    afonseca Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Problem solve!
    No need to reply!
    Thanks!

    António
     
    afonseca, Jun 1, 2006 IP