Hero Zzyzzx has asked for the wisdom of the Perl Monks concerning the following question:
I'm using CGI.pm, v 2.80 to create popup_menus from DBI queries. For some reason, the "-labels=>" option in popup_menu isn't working- I'm not getting the IDs as the values.
sub create_cat_list{ my ($type,$dbh)=@_; my $cat=$dbh->prepare("select ${type}_cat,${type}_id from ${type}_cat + order by ${type}_cat"); $cat->execute(); my @list; my %hash; while(my ($catval,$id)=$cat->fetchrow_array()){ push @list, $catval; $hash{$id} = $catval; } $cat->finish(); return [ \%hash,\@list ]; } ## SNIP my $l1=create_cat_list('l1',$dbh); $output.=$q->popup_menu(-name=>'l1_cat',-values=>$l1->[1],-labels= +>$l1->[0]);
The popup_menu doesn't end up with the -labels being applied to it. Using Data::Dumper, the hash ref comes through from create_cat_list() fine. Is this a bug in CGI 2.8.0? I completely don't understand what's going on. Data::Dumper output of create_cat_list() is below.
and here's the HTML being output.$VAR1 = [ { '1' => 'Canadian Paper Money', '2' => 'US Coins', '3' => 'US Paper Money', '4' => 'Supplies', '5' => 'Canadian Coins' }, [ 'Canadian Coins', 'Canadian Paper Money', 'Supplies', 'US Coins', 'US Paper Money' ] ];
<select name="l1_cat"> <option value="Canadian Coins">Canadian Coins</option> <option value="Canadian Paper Money">Canadian Paper Money</option> <option value="Supplies">Supplies</option> <option value="US Coins">US Coins</option> <option value="US Paper Money">US Paper Money</option> </select>
Maybe I'm missing the obvious, but what the heck is going on here?
-Any sufficiently advanced technology is
indistinguishable from doubletalk.
|
|---|
| Replies are listed 'Best First'. |
|---|