SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a button on a form that when you click it it reloads the page and adds up some prices and displays the total depending on what you selected in some pull down menus. But when the page reloads the pull down menus go back to the default selection. How could I make it so that on reload they stay the same as previously selected? Thanks!

    ------------------
    Nate - nate@jumpthru.com
    ICQ 70944023
    http://www.jumpthru.com - Unbelievable Website design!
    http://www.jumpthru.com/christian - Learn, live, love, jesus christ...

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Basically you need to add "SELECTED" to the <OPTION> tag corresponding to the currently-select VALUE, if any. This is pretty easy to do in PHP, but the code can get messy.

    Here's the most compact way I know of doing it without using functions (which I don't have time to go into). Say the value is stored in $value. Then for each <OPTION> tag, you need to add code that prints "SELECT" if the value for that tag matches $value, or "" (nothing) if it doesn't:

    <OPTION VALUE="somevalue1" <?=($value=="somevalue1")?"SELECTED":""?>>
    <OPTION VALUE="somevalue2" <?=($value=="somevalue2")?"SELECTED":""?>>
    <OPTION VALUE="somevalue3" <?=($value=="somevalue3")?"SELECTED":""?>>

    Here's how that code works:

    <?="some value?>

    is shorthand for

    <? echo("some value"); ?>

    and

    $var=(condition)?"value1":"value2"

    is shorthand for

    if (condition) {
    $var="value1";
    } else {
    $var="value2";
    }


    Thus,

    <?=($value=="somevalue3")?"SELECTED":""?>>

    is short for

    <?
    if ($value=="somevalue3") {
    echo("SELECTED");
    } else {
    echo("");
    }
    ?>



    Aren't confusing shortcuts great...? :-)

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!


    [This message has been edited by kyank (edited July 23, 2000).]

  3. #3
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, that is excactly how I did it. It just looked really messy and since there is a ton of code it makes the page load longer. I thought there just might be a easier way to do it. Thanks any ways.

    ------------------
    Nate - nate@jumpthru.com
    ICQ 70944023
    http://www.jumpthru.com - Unbelievable Website design!
    http://www.jumpthru.com/christian - Learn, live, love, jesus christ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •