9.3.1 List box

Let's read the following code.

#!/usr/bin/perl
use CGI;
use strict;
use warnings;
my $q = new CGI;

print $q->header;
print $q->start_html('Simple List Demo');

print $q->startform;
my @listvalues = ('a', 'b', 'c', 'd', 'e');
my %labels = 
  (
    'a'=>'this is a', 
    'b'=>'who is b?', 
    'c'=>'here comes c', 
    'd'=>'I am d', 
    'e'=>'who is e?'
 );
print $q->scrolling_list(
      -name=>'scrolling list',
      -values=>\@listvalues,
      -defaults=>'a',
      -size=>3,
      -multiple=>'true',
      -labels=>\%labels
      );
print $q->submit;
print $q->endform;
print $q->p('Last time, you selected the following:');
my $listItems;
my $v;
foreach $v ($q->param('scrolling list'))
{
  $listItems = $listItems.$q->li("$v (value of $labels{$v})");
}
print $q->ul($listItems);
print $q->end_html;

Now, let's disect this program.



Subsections

Copyright © 2008-05-09 by Tak Auyeung