<SELECT name="day">
    <OPTION value="please select" <? if(empty($day)) { echo "selected"; }
?>>
    <OPTION value="monday" <? if($day == "monday") { echo "selected"; } ?>>
    <OPTION value="tuesday" <? if($day == "tuesday") { echo "selected"; }
?>>
    <OPTION value="wednesday" <? if($day == "wednesday") { echo "selected";
} ?>>
    <OPTION value="thursday" <? if($day == "thursday") { echo "selected"; }
?>>
    <OPTION value="friday" <? if($day == "friday") { echo "selected"; } ?>>
</SELECT>

Obviously this is labourios to code... you can do this a lot smarter/quicker
with an array for the entire select box... have an array of days, and do a
foreach loop which writes the all the options for you, with the if
statements, etc etc.

By the way, this has nothing to do with sessions :)

It's purely about how to populate drop-down menus from an array, and how to
have the correct value selected if it exists, else showing a default
selection.

Cheers,

Justin French



on 08/07/02 9:36 PM, Steve Fitzgerald ([EMAIL PROTECTED]) wrote:

> I am designing a form using sessions in which the user inputs their
> details on page 1 and after submitting they are directed to page 2 for
> confirmation. They then have the option of editing their input (ie they
> are returned to page 1) where their previous input is reflected in the
> form fields by
> value ='<?php echo $var ?>'
> This works fine except if the input type is a drop down box, in which
> case the default <option> is shown. Is there any way around this? How
> can I show the user their previous choice in these boxes?
> Any insights would be appreciated.
> Steve
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to