in reply to How to keep the state of a drop down select box in perl

I do it the hard way...
<select name="dropdown"> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select>
and on the perl side...
my @dropdown = ('Option 1','Option 2','Option 3'); foreach $op (@dropdown) { if ($op eq $in{'dropdown}) { # I use cgi-lib.pl still... $dropdown .= "<option selected>$op</option>\n"; } else { $dropdown .= "<option>$op</option>\n"; } } # later on insert $dropdown somewhere on you're # HTML response page...
As I said, I'm sure there are easier approaches to this, but I still do it ye good ol' way...

#!/home/bbq/bin/perl
# Trust no1!

Replies are listed 'Best First'.
Re: Re: How to keep the state of a drop down select box in perl
by Adam (Vicar) on Dec 16, 2000 at 00:56 UTC
    for things like:
    <select name="dropdown"> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select>
    I usually use map:
    my @options = ( 'Option 1', 'Option 2', 'Option 3', ); @options = map { "<option>$_</option>" } @options; print '<select name="dropdown">', @options, "</select>\n";
      Yes, but... that doesn't actually output a selected option! :) The question was on how to keep the state of a dropdown box. I guess mine doesn't work either since I am only counting on a single select dropdown, and just looking over it occured to me that it would break under a multiple select.

      eeeek!

      #!/home/bbq/bin/perl
      # Trust no1!