Mutley Posted October 4, 2006 Share Posted October 4, 2006 Say if I have 3 form options:appleplumlemonWhen I select "plum" how can I make it so next time you view the form options, it is highlighted/selected? Quote Link to comment Share on other sites More sharing options...
pedrobcabral Posted October 4, 2006 Share Posted October 4, 2006 Basic html code would be:<option value="plum" selected="selected">plum</option>If you are using sessions you could use something like:<option value="plum" <?php if (isset($_SESSION['myselection'])) echo selected=\"selected\">plum";?></option> Quote Link to comment Share on other sites More sharing options...
printf Posted October 4, 2006 Share Posted October 4, 2006 If it a form by way of POST, you can do it like so.[code=php:0]$options = array ( 'apple', 'plum', 'lemon' );echo "<select name='fruit'>";for ( $i = 0; $i < sizeof ( $options ); $i++ ){ echo "<option value='" . options[$i] . "'" . ( isset ( $_POST['fruit'] ) && $_POST['fruit'] == $options[$i] ? " selected='selected'" : null ) . ">" . $options[$i] . "</option>";}echo '</select>';[/code]me! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.