in reply to Re: Re: Re: Checkbox values
in thread Checkbox values

I do absolutely understand that feeling of "oh hell, I can't be bothered with this" that one gets when one Reads The Fine Manual... after all, the following sentence is scarcely written for the benefit of people who don't already pretty much know the score:
The optional fifth argument is a pointer to an associative array relating the checkbox values to the user-visible labels that will be printed next to them (-labels).
BUT... it is SO worthwhile getting through the pain barrier. It's seldom as tough as it looks, and once learned it saves time after time.

Where it says
a pointer to an associative array relating the checkbox values to the user-visible labels
what it means is "set up a hash where the keys are what you want as the checkbox values, and the values are what you want the user to read" - i.e. something like:
my %checkbox_items = ( a => 'BillJ may have been assigned as trustee to the security obje +ct which gives him supervisor rights over all NDS objects', b => 'BillJ may be wearing pink pyjamas when he comes round the mo +untain', c => 'BillJ may be the first man to orbit Mars on a unicycle', d => 'BillJ may be just another Perl hacker', );
Now, to avoid confusion, you should probably construct your array of checkbox values from this hash - that way you're sure there's always going to be a match between the values and the labels. So do
my @checkbox_values = keys %checkbox_items;
Then you put it all together by adding the -labels argument when you call the checkbox_group method:
print start_html, checkbox_group( -name => 'testing', -values => \@checkbox_values, -linebreak => 1, -labels => \%checkbox_items, ),
And this will print out the following HTML (line breaks added for clarity:
<input type="checkbox" name="testing" value="a" /> BillJ may have been assigned as trustee to the security object which g +ives him supervisor rights over all NDS objects <br /> <input type="checkbox" name="testing" value="b" /> BillJ may be wearing pink pyjamas when he comes round the mountain <br /> <input type="checkbox" name="testing" value="c" /> BillJ may be the first man to orbit Mars on a unicycle <br /> <input type="checkbox" name="testing" value="d" /> BillJ may be just another Perl hacker <br />
Hope that does what you want to do in an intelligible way. One other thought - about saving memory. A point frequently made round here, for example by by dragonchild, is that Perl is optimised not for CPU or memory use, but for that scarcest and most valuable of computer consumables... developer time. I.e. YOUR time. So if a thing is quicker to write but slower to run, write it that way and then $RAM->buy('more');

§ George Sherston

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Checkbox values
by chriso (Sexton) on Nov 20, 2001 at 01:50 UTC
    Your explaination was great! Thanks for the example. For me, a picture is worth a thousand words. Chris