Home: Perl Programming Help: Intermediate:
checkbox_group how to check all values


Jan 16, 2004, 5:43 AM

Views: 716
checkbox_group how to check all values


I have been trying for a long time to get all the checkboxes (using CGI.pm) in a checkbox_group checked by using the attribute defaults;

checkbox_group(-name=>'studenten_in_groep', -values=>\@member_keys, -defaults=>\@member_keys, -labels=>\%temp_members, -columns=>2)

I can not get this to work, no boxes are checked and there are no errors, it seems to be ignored competely!

When i give the param('studenten_in_groep') a value before i call on the checkbox_group, it does check all the boxes;

param('studenten_in_groep' => @member_keys);

Is it not possible to use the defaults attribute the way i am trying to? If i look at examples on cpan it looks like i am doing it the correct way..

Any ideas?


Thaumaturge / Moderator

Jan 17, 2004, 3:47 AM

Views: 715
Re: [tine] checkbox_group how to check all values

What data do you have in @member_keys and %temp_members?

It all seems to work as expected for me.


use strict;
use warnings;

use CGI qw(:standard -no_xhtml);

my @member_keys = 1 .. 5;
my %temp_members = (1 => 'one', 2 => 'two', 3 => 'three',
4 => 'four', 5 => 'five');

print checkbox_group(-name=>'studenten_in_groep',

I get the following output (slightly reformatted for clarity)

<td><input type="checkbox" name="studenten_in_groep"
value="1" checked>one</td>
<td><input type="checkbox" name="studenten_in_groep"
value="4" checked>four</td>
<td><input type="checkbox" name="studenten_in_groep"
value="2" checked>two</td>
<td><input type="checkbox" name="studenten_in_groep"
value="5" checked>five</td>
<td><input type="checkbox" name="studenten_in_groep"
value="3" checked>three</td>

As you can see, all of the checkboxes have the "checked attribute, so they will appear as selected when the page is displayed in a browser.

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks