in reply to Adding attributes to select list options in CGI.pm popup_menu?

I want to replicate that -title=> behaviour in popup_menu()

The manual is very clear http://search.cpan.org/dist/CGI/lib/CGI.pm#CREATING_A_POPUP_MENU

#!/usr/bin/perl -- use CGI; print CGI->popup_menu( -values => ['a', 'b'], -labels => {'a', 'labela', 'b', 'labelb'}, -attributes => { 'a' => { title => 'titlea' }, 'b' => { title => 'titleb' }, }, ); __END__ <select name="" > <option title="titlea" value="a">labela</option> <option title="titleb" value="b">labelb</option> </select>
  • Comment on Re: Adding attributes to select list options in CGI.pm popup_menu?
  • Download Code

Replies are listed 'Best First'.
Re^2: Adding attributes to select list options in CGI.pm popup_menu?
by backedge (Initiate) on Jun 30, 2011 at 13:59 UTC

    My problem was actually in populating my %titles_prd_order_allowed, which I didn't include, trying to keep it short - sorry. Sorted now, thanks.

    my @low_values_prd_order_allowed = (); my %meanings_prd_order_allowed = (); my %titles_prd_order_allowed = (); my $stmt = "SELECT value, meaning, title FROM OPTIONS "; my $sth = $dbh->prepare($stmt); $sth->execute(); while ( ( $value, $meaning, $title ) = $sth->fetchrow_array() ) { push( @low_values_prd_order_allowed, $value ); $meanings_prd_order_allowed{$value} = $meaning; $titles_prd_order_allowed{$value} = ( $value =>{'title'=> $title} ); } print $q->label( { -for => 'idprd_order_allowed' }, "ORDER ALLOWED" ); print $q->popup_menu( -id => 'idprd_order_allowed', -name => 'prd_order_allowed', -override => 1, -onChange => "changeInCore=true", -default => $prd_order_allowed, -value => [@low_values_prd_order_allowed], -labels => \%meanings_prd_order_allowed, -attributes => \%titles_prd_order_allowed );

    I (being a numpty) previously had:

    $titles_prd_order_allowed{$rv_low_value} = $title;