The posters so far don't seem to have looked up the CGI perldoc before posting. In any case, in order to create a popup menu with labels different from the values, you need to be using both the -values parameter and the -labels parameter. This first of those takes a list reference, and the second a hash reference. So let's take a look at what they require.

As it stands now, you're passing into -values a structure like this:

[ { '1' => { 'Author' => 'Mike', 'idAuthor' => '1' }, '2' => { 'Author' => 'Cecil', 'idAuthor' => '2' } } ]
when what you need to do is pass a structure like this as the -values parameter: [ '1', '2' ], and this as the -labels parameter:
{ '1' => 'Mike', '2' => 'Cecil' }
So the question is, how do you go from one to the other? As with many structure reformulations, the answer is with a clever use of map:
my $values_list = [ sort(keys(%$hash_ref)) ]; my $labels_href = { map {$_->{idAuthor} => $_->{Author}} values(%$hash_ref) }; print $cgi->popup_menu(-name=>'menu_name', -values=>$values_list, -labels=>$labels_href);
If you don't like the order authors are shown in once you have ten or more, change the sort call above so that it sorts numerically.
--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

In reply to Re: CGI's "popup_menu" Using Hash Reference by fizbin
in thread CGI's "popup_menu" Using Hash Reference by awohld

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.