Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

cgi.pm: popup_menu

by slackah (Initiate)
on Mar 14, 2003 at 19:05 UTC ( [id://243151]=perlquestion: print w/replies, xml ) Need Help??

slackah has asked for the wisdom of the Perl Monks concerning the following question:

I'm using CGI.pm and i want to pass a hash to the popup_menu function so it will create all my select fields.

On perldoc it says the following:
%labels = ('eenie'=>'your first choice', 'meenie'=>'your second choice', 'minie'=>'your third choice'); print $query->popup_menu(-name=>'menu_name', -values=>['eenie','meenie','minie'], -default=>'meenie', -labels=>\%labels);
I don't want to have to type in the all the values manually though. Could someone tell me how to pass the hash keys for the values? The same as is done for the -labels? \%labels for the values field passes the hash values.

edited: Fri Mar 14 23:31:30 2003 by jeffa - code tags

Replies are listed 'Best First'.
Re: cgi.pm: popup_menu
by crenz (Priest) on Mar 14, 2003 at 19:24 UTC

    keys %labels should do the trick.

      the -labels attribute expects an array reference, not a list, so that should instead be -labels => [ keys %labels ]

      the [ ] around the keys %labels makes it an anonymous array, which is a reference to an array with no name.

      HTH

      If not P, what? Q maybe?
      "Sidney Morgenbesser"

      its not working though, and when i do this

      my @temp = keys %labels;
      my $temp2;
      foreach(@temp) {
      $temp2.="'$_'";
      $temp2.=",";
      }
      chop $temp2;

      print $q->popup_menu(-name=>'menu_name', -values=>$temp2, -default => $q->param('product'), -labels=>%labels);

      It just prints $temp2 as one value.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://243151]
Approved by Thelonius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-28 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found