[lug] Perl CGI Question
Zan Lynx
zlynx at acm.org
Wed Aug 6 15:11:45 MDT 2003
On Wed, 2003-08-06 at 13:45, Joseph McDonald wrote:
[snip]
> I'd like to have the second page display the previously
> submitted value in the newly printed select query. The
> way to do this would be to print:
>
> print qq|<OPTION VALUE="Apr" selected>Apr \n|;
>
> in the return page, had Apr been selected. I just can't think
> of an easy way to do that. The only way I can think of doing
> it would be an if/else statement for each option value which
> seems ridiculous. Any ideas?
>
> --joey
[snip code]
Data structures, not code!
What you want to do is make an array containing the selection options.
As you loop through the array, check each element for a match with what
the user selected. When you find the match, print "selected" in that
option.
Something like:
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
foreach (@months) {
print "<option value=\"$_\"";
print " selected" if $_ eq param();
print ">\n";
}
--
Zan Lynx <zlynx at acm.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20030806/620a6d53/attachment.pgp>
More information about the LUG
mailing list