in reply to CGI form element sizing issue
use warnings; use strict; use CGI::Pretty qw(:standard); # plain CGI will do too #========================================== my %id_to_term = ( 92 => 'Tuna', 3 => 'Ceolocanth', 4 => 'Ratfish', 7 => 'Six Gill Shark', 13 => 'Albino Pygmy Sperm Whale', ); print header(), start_html(), start_form(); print h3("Regular"), popup_menu( -labels => \%id_to_term, -values => [ sort keys %id_to_term ], ); print h3("Shortened"), popup_menu( -style => "font-size:75%;", -labels => \%id_to_term, -values => [ sort keys %id_to_term ], ); print h3("Moreso"), popup_menu( -style => "font-size:60%;", -labels => \%id_to_term, -values => [ sort keys %id_to_term ], ); # now we modify the values with word_chop since we're able to look up # by the IDs anyway, it doesn't matter that we modify them my %id_to_chopped_term = %id_to_term; while ( my ( $id, $term ) = each %id_to_chopped_term ) { $id_to_chopped_term{$id} = word_chop($term, 12); } print h3("Okay, that's ridiculous"), popup_menu( -style => "font-size:50%;", -labels => \%id_to_chopped_term, -values => [ sort keys %id_to_chopped_term ], ); print end_form(), end_html(); exit 0; #=========================================== sub word_chop { my ( $text, $chars ) = @_; $chars ||= 15; return $text if $chars >= length $text; return substr($text, 0, $chars) . '...'; }
|
|---|