in reply to What's the REAL DEAL with Perl $cgi->checkbox()
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What's the REAL DEAL with Perl $cgi->checkbox()
by Your Mother (Archbishop) on Feb 03, 2015 at 19:54 UTC | |
by kennethk (Abbot) on Feb 03, 2015 at 21:22 UTC | |
by misterperl (Friar) on Oct 16, 2015 at 21:01 UTC |