php select list stay selected

Discussion in 'PHP' started by jacka, May 23, 2007.

  1. #1
    Hi

    As part of a big project I have undertaken, I need to alter various portions of my php codes.
    The portion that was originally and was working fine was this:

    ----
    <select name="price_break" size="1" onChange="range(this)">
    <?php

    for($i = 1; $i <= 8; $i++)
    {

    echo "<option ";

    if($startnumber == $i)
    {
    echo " SELECTED ";
    }
    echo ">" . $i . "</option>";
    }
    ?>
    ---

    This enabled the option the user chose to stay selected.
    But now I need to show afew more data, in the otions list and I am stuck as how to make sure that the chosen item stays selected after teh used makes his/her choice.

    <select name="price_break" size="1" onChange="range(this)">
    $c=$row["price_each1"];// price for single item




    for($i = 1; $i <= 8; $i++)
    {
    $b=$row["price_each".$i];

    $d=(($c-$b)/$c)*100;

    echo "<option> ";

    echo $row[("price_break".$i)]. " ," .round($d)."%" . "</option>";




    }

    ?>

    </select>
    ---
    This last snippet of code works but without the selected item stay selceted on refresh.

    Can some one please help.
    p.s. I have thought and researched alot before submitting this question.
    :(
     
    jacka, May 23, 2007 IP
  2. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sorry , you might also need to know the fucktion UpdateQty(item)--


    function UpdateQty(item)
    {
    itemId = item.name;
    newQty = item.options[item.selectedIndex].text;

    document.location.href = 'cartnew.php?action=update_item&id='+itemId+'&qty='+newQty;
    }
     
    jacka, May 23, 2007 IP