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

Using CGI.pm Does anybody know if its possible to add a span with a style to the label element that are generated by the checkbox_group or do i need to roll my own routine to do this?

ie <label> <span style="background-color:#345643; "> <input type="checkbox" ....... </span> </label>
John Digging through the code I found about LABELATTRIBUTES So you can do this. SO you can apply a style -labelattributes => "" It not the same as -attributes tag which is reference to hash, were you have the attribute's name as the key and the attribute's value as the value. But, I want to apply a different background color to subset of the checkboxes.

Replies are listed 'Best First'.
Re: CGI.PM checkbox_group
by thewebsi (Scribe) on Aug 23, 2013 at 06:25 UTC

    You would have to use something different to get exactly that output, eg:

    print label ( span ({ style => "background-color: #345643;" }, input ( +{ type => "checkbox" }) ) );

    However, in practice I find that CSS can achieve desired results without additional tags. In your particular example,
    print '<span style="background-color: #345643;">' . checkbox_group ({ values => "" }) . '</span>';
    achieves the same effect. Of course your "real" scenario may be more complicated.

      Have a patch for the CGI.pm module
      if ($XHTML) { push @elements, CGI::label($labelattributes, qq(<input type="$box_t +ype" name="$name" value="$_" $checkit$other$tab$attribs$disable/>$lab +el)).${break}; } else {

      to

      if ($XHTML) { my $labelattr = ref $labelattributes eq 'HASH' ? $labelattributes-> +{$_} : $labelattributes ; push @elements, CGI::label($labelattr,