Re: Remembering which option in a SELECT tag the user had chosen
| From: | Jason Wong | Date: | Wed, 29 Jan 2003 07:24:25 +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-133463@lists.php.net to get a copy of this message | ||
On Wednesday 29 January 2003 12:48, Webapprentice wrote:
> 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
[snip]
> 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?
The way to do it is to programmatically output the <SELECT> element.
Store the options in an array, then step through the array building up the
<SELECT> and <OPTION> tags inserting "selected" where appropriate.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
You seek to shield those you love and you like the role of the provider.
*/