Hi Monks,

I have a very large form that is mailed to several aliases determined by mapping a country name to a region. I have a list of all countries and their respective regions in a text file formatted this way:

... namerica:united states samerica:brazil ...

So North America has an alias, South America has one and so on. In my CGI, I built a pull down from this list from that file and have a sub that maps to the correct regional email alias.

The problem: I need to call the sub that generates the pull down more than once. Here is some sample code to try and reiterate/illustrate what I am trying to accomplish

#the email part of the CGI ... Country: $param{country} ... #sub to create HTML pull down sub generateCountries{ my (@all_countries, $HTML_String); open(FILE, "<countries.txt") or die "cannot read file"; while(<FILE>){ if(/(.*):(.*)/i){ push @all_countries, $1; } } my $HTML_String = "\t" . '<select name = "country"> <option name="country" value="">-- Select a Country --</option +>'; for(my $i = 0; $i < $#all_countries; $i++){ $HTML_String .= "\t\t" . '<option value = "' . $all_countries +[$i] . '">' . $all_countries[$i] . "</option>\n"; } $HTML_String .= "\t</select>"; return $HTML_String; #the HTML form call to CGI that prints pull down <td> Country:</td><td colspan='2'> <?pp:CALL:ALL_COUNTRIES?></td></td>

Any suggestions on how to make this work with out having to write that whole sub over and over again (I need 4 pull downs), so I will end up with something more like this:

... Country : $param{country} Country1: $param{country1} Country2: $param{country2} ...
Thanks All

CSUhockey3


In reply to dynamic HTML pull down by csuhockey3

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.