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

Hallo monks,

i have a little cgi problem.
I want to make a checkbox_group (cgi.pm) and to put it in a table column (rowspan). The idea is to select items named in the column right to this column. It works, but not in an optimal way. The boxes are not aligned with the table cells.
Is it possible to make it better?

Murcia

------------------ how it should look like: boxes items ____________ |_| item1 |_| item2 |_| item3
$colgroup = $cgi->checkbox_group( -name=>'embl_group', -values=>[@fieldArray], #-rows=>1, -columns=>1, -nolabels=>1, -linebreak=>'true' ); if(defined $fields){ $rows = $cgi->th({-align=>'left'}, ''); for(my $i = 0; $i < @$fieldNames; $i++){ $rows .= $cgi->th({-align=>'left'}, $fieldNames->[$i]); } my $numberFields = @$fields; for( my $i = 0; $i < @$fields; $i++){ $rows .= $cgi->start_Tr(); $rows .= $cgi->td({'-valign'=>'middle', -rowspan=>$numberField +s}, $colgroup) if $i == 0; $rows .= $cgi->td({'-valign'=>'middle', -height=>22}, $fields- +>[$i]); $rows .= $cgi->end_Tr(); } }

20030408 Edit by Corion: Added formatting and CODE tags

Replies are listed 'Best First'.
Re: cgi checkbox_group in table
by benn (Vicar) on Apr 08, 2003 at 12:37 UTC
    Whenever you're doing things like this with CGI.pm HTML commands, you need know what you want your final HTML code should look like first. In this case, it's difficult to see out of context, but certainly things like having 'th' tags outside of a 'tr' at the top there will confuse a browser. Try constructing your 'ideal' HTML layout manually, then comparing the results from your script.
    Using tables for layout can often get messy, and I would always prefer a pure-CSS layout, but even just adding a CSS class to the table would mean that you could then experiment with layouts (.mytable td {text-align:left;} etc.) without changing your perl code.
    From what it looks like you're trying to achieve though, I think defining a style for the checkbox group and then playing with *its* layout would serve you better - you could then use the inbuilt group labels and size/align them as you want, rather than have a bunch of code to print them separately.
    Cheers
    Ben
Re: cgi checkbox_group in table
by MrCromeDome (Deacon) on Apr 08, 2003 at 15:55 UTC
    CGI and Perl will let you easily label your checkboxes. See the following (untested) sample:
    my @values; my %labels; foreach(1..10) { $values[$_] = $_; $labels{$_} = "Item $_"; } $colgroup = $cgi->checkbox_group( -name=>'embl_group', -values=>\@values, -labels=>\%labels, -linebreak=>'true' );
    This will let you have your item names and checkboxes that correspond with them in the same cell of the table. This should take care of your alignment problem.

    Hope this helps!
    MrCromeDome