2. The optional second parameter (-checked) specifies that the checkbox is turned on by default. Synonyms are -selected and -on.So, if you omit -checked, the box is unchecked. I'd say this is fairly straightforward, though I would have implemented it with a boolean evaluation myself.
The only way I can find to toggle checked-by-default is to have two seperate statements with logic , one WITH -checked and one without, which is more 2X the syntax I want to use.Assuming you want a branch, there must be a test in any case. To handle the branching, you could use the ternary Conditional Operator with a list argument:
And, to be fair, weird accumulated crufty behavior is exactly why CGI.pm has been removed from the Perl core.print checkbox(-name=>'checkbox_name', $checked ? (-checked=>1) : (), -value=>'ON', -label=>'CLICK ME');
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
In reply to Re: What's the REAL DEAL with Perl $cgi->checkbox()
by kennethk
in thread What's the REAL DEAL with Perl $cgi->checkbox()
by misterperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |