Re: Remembering which option in a SELECT tag the user had chosen

From: Date: Wed, 29 Jan 2003 11:19:03 +0000
Subject: Re: Remembering which option in a SELECT tag the user had chosen
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-133480@lists.php.net to get a copy of this message
> Hi, > I have a SELECT on a web form. > > <select name="TimeChoice"> > <option value="Friday August 22, 04:00 PM - 06:00 PM">Friday August 22, 04:00 PM - 06:00 PM</option> > <option value="Friday August 22, 06:00 PM - 08:00 PM">Friday August 22, 06:00 PM - 08:00 PM</option> > <option value="Friday August 22, 08:00 PM - 10:00 PM">Friday August 22, 08:00 PM - 10:00 PM</option> > <option value="Friday August 22, 10:00 PM - 12:00 AM">Friday August 22, 10:00 PM - 12:00 AM</option> > <option value="Saturday August 23, 12:00 AM - 02:00 AM">Saturday August 23, 12:00 AM - 02:00 AM</option> > <option value="Saturday August 23, 12:00 PM - 02:00 PM">Saturday August 23, 12:00 PM - 02:00 PM</option> > <option value="Saturday August 23, 02:00 PM - 04:00 PM">Saturday August 23, 02:00 PM - 04:00 PM</option> > <option value="Saturday August 23, 04:00 PM - 06:00 PM">Saturday August 23, 04:00 PM - 06:00 PM</option> > <option value="Saturday August 23, 06:00 PM - 08:00 PM">Saturday August 23, 06:00 PM - 08:00 PM</option> > <option value="Saturday August 23, 08:00 PM - 10:00 PM">Saturday August 23, 08:00 PM - 10:00 PM</option> > <option value="Saturday August 23, 10:00 PM - 12:00 AM">Saturday August 23, 10:00 PM - 12:00 AM</option> > <option value="Sunday August 24, 12:00 AM - 02:00 AM">Sunday August 24, 12:00 AM - 02:00 AM</option> > <option value="Sunday August 24, 12:00 PM - 02:00 PM">Sunday August 24, 12:00 PM - 02:00 PM</option> > <option value="Sunday August 24, 02:00 PM - 04:00 PM">Sunday August 24, 02:00 PM - 04:00 PM</option> > </select> > > Only one option may be chosen > > When I submit this form, there could be errors. When I have errors, I > wish to reprint the form with the user's values remembered. In the > reprinted SELECT tag, one of the OPTION tags will now have a SELECTED > attribute. Is there any elegant way to insert the SELECTED attribute on > the right option? Unless you come up with a nice function to create this box for you, then the only way is to go in on each line, in each <option> tag and check $_POST['TimeChoice'] (or $_GET, $_REQUEST, whatever...) to see if it equals the current value. <option value="Friday August 22, 04:00 PM - 06:00 PM"<? if($_POST['TimeChoice']=="Friday August 22, 04:00 PM - 06:00 PM") { echo " SELECTED"; }?>>Friday August 22, 04:00 PM - 06:00 PM</option> ---John Holmes...

« previous php.general (#133480) next »