[lug] Perl CGI Question

Joseph McDonald joem at uu.net
Wed Aug 6 15:46:00 MDT 2003


Thanks you guys. I've added the day of the month the same 
way (1 .. 31) and it works great! 

	--joey

On Wed, Aug 06, 2003 at 03:11:45PM -0600, Zan Lynx wrote:
> 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>





More information about the LUG mailing list