here is the browser/server interaction --

On the browser you have a form (btw, your syntax is wrong)

<form> <select name="month" size="1"> <option value="">Select a month</option> <option value="0305">March 2005</option> <option value="0405">April 2005</option> <option value="0505">May 2005</option> <option value="0605">June 2005</option> <option value="0705">July 2005</option> </select> <input type="submit"> </form>

The user selects a month and hits submit. That action sends a form variable called month back to the server. Perl on the server grabs the form variable and stuffs it in a var like so --

my $month = $cgi->param('month'); # You are using CGI or CGI::Simple, are you not? # now do whatever you want with that $month

You want to actually generate the above form using Perl.

# here is one of the million ugly ways of doing this. # The better way would be to use a templating system. my @months = qw(03March 04April 05May 06June 07July); print makeform(); sub makeform { my $form = "<select name='month' size='1'>\n"; $form .= "<option value=''>Select a month</option>\n"; for (@months) { $_ =~ /(\d\d)(.*)/; $form .= "<option value='" . $1 . "05'>" . $2 . "2005</option>\n"; } $form .= "</select>\n"; return $form; }

yeewww. I haven't done that kind of code in a long time. Made me feel kinda dirty. I don't think I have written a web app without HTML::Template in 3 years.

Update: corrected stupid typos and mistakes in bad, ugly code. Reason #467 to use a templating system.

--

when small people start casting long shadows, it is time to go to bed

In reply to Re: Extracting selected values from HTML Select Menus by punkish
in thread Extracting selected values from HTML Select Menus by kjg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.