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.
In reply to Dynamically marking a HTML select option as selected by ezekiel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |