[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] CGI scrolling_list



=Mike wrote:
   I'd like to use an array as part of an argument to scrolling_list
   (part of CGI module) ...  Here's something to give the idea:

   #!/usr/bin/perl -w
   use CGI qw(:standard :html3);
   @city = qw(Dallas Phoenix Tucson Lompoc);
   print "@city\n";
   print scrolling_list(-name=>'mapList', -values=>["test1", "test2"],
     -size=>8, -multiple=>'true');

   ... how can I put the @city array into the
   scrolling_list command? Everything I've tried has met with no success.

   Mike Schienle <mgs@ivsoftware.com>

Keary wrote:
   The values parameter takes a reference to an array or list. Check the
docs
   for references and you will find your answer.


Hi Mike,

you have to use    \   for referencing your   @cities  list.

=cut

#!/usr/bin/perl -w
use CGI qw(:standard :html3);

@cities = (Dallas, Phoenix, Tucson, Lompoc);
print "@cities\n";

print scrolling_list(
  -"name"    => 'mapList',
# -"values"  => ["test1", "test2"], ## this is the anonymous list reference
of ("test1", "test2")
  -"values"  => \@cities,  ## likewise: referencing  @cities
  -"size"    => 8,
  -"multiple"=> "true");


=One more remark: I tried CGI.pm, and found it behaves
strangly-unobidiously;
sometimes it might be a good idea to construct your menu without
that questionable CGI.pm;
something like that:
=cut

@cities = (Oslo, Helsinki, Berlin, Paris, London, Hattstedt);
$MyVillage = "Hattstedt";

sub build_menue { my $k;
  $k .= "\n"
     .'<select NAME="Cities" multiple OnClick=submit()>';
  for (@_) {
    $k .= "\n<option ";
    if ($_ eq $MyVillage) {
      $k .= 'selected ' }
    $k .= 'value="'. $_ . '">' . $_;  }
  $k .= '</select>';
  return $k     }

print "\n<form>",
      build_menue(@cities),
      "\n</form>";


=output:

<form>
<select NAME="Cities" multiple OnClick=submit()>
<option value="Oslo">Oslo
<option value="Helsinki">Helsinki
<option value="Berlin">Berlin
<option value="Paris">Paris
<option value="London">London
<option selected value="Hattstedt">Hattstedt</select>
</form>


=Detlef Lindenthal <detlef@lindenthal.com>








# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org