SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Redisplay values submitted from a select box

    I've been looking for almost a week on a reliable way to redisplay values submitted from a select box on a second page.No luck so far.Could be lucky here to get someone to end this puzzle for me?

    <select name="options">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If by "redisplay values" you mean that you want to display the select box with the previously selected item as the default, then you want to add 'selected="selected"' to the option tag:
    HTML Code:
    <select name="options">
    <option value="1">1</option>
    <option value="2" selected="selected">2</option>
    <option value="3">3</option>
    I don't know how your select box is being generated, but in general these things are done in loops similar to thus:
    PHP Code:
    while(some_condition)
    {
        echo 
    "<option value=\"$value\"";
        if(
    $value==$_POST['options'])
            echo 
    " selected=\"selected\"";
        echo 
    ">$name</option>\n";

    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Kromey for your response !
    yes,that is correct,load and default to previously submitted select input.
    My drop down is simply html generated.
    Can you please elaborate a bit on what to put as a condition in:
    while(some_condition)
    so i think you only output the $name as an example(option1)

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function DisplayMenuChoices$selected ="") {
        
    /* Put all of your menu choices in an array */
        
    $list = array( "Bar"
                        
    "Foo",
                        
    "Ipsum",
                        
    "Lorem"
                        
    );
        
        echo 
    "<select name='Field_Name '>\n"// Replace Field_Name with your data field name
        
    foreach ( $list as $name ) { // Set up loop to walk array
            
    if ( $name == $selected ){ // Check for the value the user has selected
                
    echo "    <option selected='selected'>$name</option>\n"// Option selected
            
    } else {
                echo 
    "    <option>" .$name"</option>\n"// Option not selected
            
    }
        } 
        echo 
    "</select>\n"// End select list

    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  5. #5
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately,none of the above worked for me so far .


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
  •