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

Fellow monks,

I'm using CGI for a simple shopping cart script and I'm running in to some unexpected behaviour from the single checkbox function.

Given the following snippet of code:

$query->td({-colspan => 2, -width => '100%', -bgcolor => 'blue'}, $query->font({-color => 'white', -size => '-1', -face => 'arial, he +lvetica'}, $query->b('Shipping Information')). $query->font({-color => 'white', -size => '-2', -face => 'arial, he +lvetica'},' (Check to use Billing Information:)'). $query->checkbox(-name => 'copy', -value => 'off', -OnClick => 'jav +ascript:ShipToBillPerson(this.form);') )

which outputs this in the html genereation

<td bgcolor="blue" width="100%" colspan="2"> <font face="arial, helvetica" color="white" size="-1"> <b>Shipping Information</b> </font> <font face="arial, helvetica" color="white" size="-2"> (Check to use Billing Information:) </font> <input type="checkbox" name="copy" value="" onclick="javascript:Ale +rt('Checked!');" /> copy </td>

My question is, why the text "copy" is being inserted. I thought that naming the checkbox element was for referencing it through the param function? If I eliminate the -name part, I won't be able to see if it was checked will I? Also since "copy" is showing up in my text, what have I missed to eliminate "copy" as text on the page?

Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.

Replies are listed 'Best First'.
Re: CGI.pm checkbox question
by ikegami (Patriarch) on Apr 29, 2005 at 16:45 UTC

    Quote the docs: "The optional fourth parameter (-label) is the user-readable label to be attached to the checkbox. If not provided, the checkbox name is used." Try

    $query->checkbox( -name => 'copy', -label -> '', -value => 'off', -OnClick => ... )

    instead of

    $query->checkbox( -name => 'copy', -value => 'off', -OnClick => ... )
Re: CGI.pm checkbox question
by jhourcle (Prior) on Apr 29, 2005 at 16:46 UTC
Re: CGI.pm checkbox question
by Popcorn Dave (Abbot) on Apr 30, 2005 at 01:39 UTC
    Thanks for that! I can't believe the solution was so obvious I missed it. (/me slinks away to do pennance with the docs )

    Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.