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

Is there some sort of parameter for a scrolling list that can keep it the same width? My problem is the width of the scrolling list varies depending what is in it. For instance, when it is blank it is very thin, and when you put long lines of text in it, it expands to take up a lot of space. I am aware of the size parameter, but it only seems to govern the height of the scrolling list. I have looked all over and I have been unable to find an answer to this question. I guess no one likes to use scrolling lists.

Replies are listed 'Best First'.
Re: Scrolling Lists
by cwest (Friar) on Jul 20, 2000 at 21:52 UTC
    This code will keep your box as long as your longest value.
    my @values = qw/ One Two Three Four Zoobdude(_Been_to_Dennys?_:) /; my $longest = 0; map { $longest = length > $longest ? length : $longest } @values; printf "<option value='$_'>%${longest}s\n", $_ foreach @values;
    Update: You wanted to use CGI.pm? Ok, this time we'll use a fixed width of 40 chars:
    my @values = qw/ One Two Three Four Zoobdude(_Been_to_Dennys?_:) /; my %popup; $popup{$_} = sprintf "%40s",$_ foreach @values; print $cgi->popup_menu( -name => 'popup', '-value' => [ keys %popup ], '-labels' => \%popup, ),"\n";
    Enjoy!
    --
    Casey
    
      would this work if the scrolling list is empty?
        Honest answer: Beats me, try it!

        Guess: The first example wouldn't work, the second, I'm 95% sure.

        You man have to initialize the list to one blank element, ' ' for example.

        --
        Casey
        
Re: Scrolling Lists
by athomason (Curate) on Jul 20, 2000 at 21:42 UTC
    Sorry, no. The CGI.pm method scrolling_list implements a <SELECT> tag, which (according to my IE/NS4 reference) has three attributes: name, size, and multiple. size only controls the height, so it would seem that width is browser-determined.

    I would strongly recommend against it, but maybe you could wedge the box in a frame (blech!) if it was absolutely critical to have a constant size. Preferably, however, just modify your dataset to make sure it's a decent size, either by padding an entry or truncating long ones.

Re: Scrolling Lists
by le (Friar) on Jul 20, 2000 at 21:36 UTC
    Plain HTML can't do that. Maybe you're lucky using CSS, but I'm almost sure that this works only for one of the major browsers, if any at all.