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

Hello esteemed monks,

I contruct a checkbox group with an @array of elements. Is there anyway to determine the user selected the nth element(s) rather than the name. For example:

@metrics=`cat a.txt`; print $query->checkbox_group(-name=>'a', -values=>\@metrics, -columns=> 1), ...

Replies are listed 'Best First'.
Re: checkbox CGI
by vivapl (Acolyte) on Aug 07, 2003 at 14:50 UTC

    If I'm not mistaken, you can assign the values to the checkboxes with labels. Now the labels is what you will see on the page, however the values you will not. By clicking the checkbox, you should be able to get the value.

    So for example you can use -values to index your checkboxes and lables to display 'a.txt' content.

    Here is a sample:

    print $query->checkbox_group(-name=>'name', -values=>\@metrics_index, -linebreak=>'true', -labels=>\%metrics, -columns=>1);

    Hope this helps and that's what you looking for

Re: checkbox CGI
by davorg (Chancellor) on Aug 07, 2003 at 14:42 UTC

    (untested)

    @metrics=`cat a.txt`; my %labels; @labels[ 0 .. $#metrics ] = @metrics; print $query->checkbox_group(-name=>'a', -values=> [ 0 .. $#metrics ], -labels=> \%labels, -columns=> 1),
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: checkbox CGI
by benn (Vicar) on Aug 07, 2003 at 14:47 UTC
    You could provide numbers as values, and your original values as labels, something like this...
    my @metrics=`cat a.txt`; my %labels = map {$_=> $metrics[$_]} (0..$#metrics); print $q->checkbox_group(-name=>'a', -values=>[(0..$#metrics)], -labels=>\%labels);
    Cheers, Ben.