ezekiel has asked for the wisdom of the Perl Monks concerning the following question:
I have an CGI application where a user can create a database entry by completing an HTML form. Later, the user may want to retreive an entry, edit it, and store it back in the database. I plan to do this by extracting the values from the database and producing the same HTML form but with these values inserted as the "default" values.
This works fine for text boxes by just adding a value="$existing_value" to the <input type="text" name="my_parameter"> widget. However, I run into a problem when using a <select> widget.
The only way I can think of doing it is to put it inside an if/then statement as such:
if ($existing_value eq "option1") then { $html .= qq| <select name="my_parameter"> <option value="option1" selected>Option 1 <option value="option2">Option 2 </select> |; } elsif ($existing_value eq "option2") then { $html .= qq| <select name="my_parameter"> <option value="option1">Option 1 <option value="option2" selected>Option 2 </select> |; }
This is really ugly, especially if the select has a large number of possible options. Does anyone have any better suggestions as to how this might be done? Any modules that may help?
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamically marking a HTML select option as selected
by chip (Curate) on Dec 19, 2001 at 12:03 UTC | |
|
Re: Dynamically marking a HTML select option as selected
by Chmrr (Vicar) on Dec 19, 2001 at 13:11 UTC | |
by mortis (Pilgrim) on Dec 19, 2001 at 20:13 UTC | |
|
Re: Dynamically marking a HTML select option as selected
by joealba (Hermit) on Dec 19, 2001 at 10:36 UTC | |
|
Re: Dynamically marking a HTML select option as selected
by Juerd (Abbot) on Dec 19, 2001 at 12:45 UTC |