in reply to How to keep the state of a drop down select box in perl
I think you are asking about the SELECTED modifier to the OPTION tag. Don't hard code it, however, because it may change. Use a simple test to see whether or not to include it. In the example below, the variable $color has already been set. Note that is $color does not match anything, the browser will show the first OPTION as the selected one.
@colors = ("red", "blue", "green", "cyan"); print "<SELECT NAME=\"MyColor\">\n"; for $x (@colors) { printf "<OPTION%s>$x", $color eq $x ? " SELECTED" : ""; } print "</SELECT>\n";
|
|---|