in reply to checkbox help

but I want it to write something like "no data" so that everything lines up.

if (/^c_/) { $check{$_} = "CHECKED" print OUT "$in{$_}\t"; } else { print OUT "no data\t"; # or just "\t" }

why is $check{$_} being set to "CHECKED" everytime?

The checkbox will only be present in the list of params if it is checked.

Replies are listed 'Best First'.
Re^2: checkbox help
by djbryson (Beadle) on Mar 05, 2007 at 18:18 UTC
    that didn't work.... because i'm printing out more than just checkbox data. Here's the whole sub routine:
    sub getdata { # $_ is the form element name and $in{$_} is the cont +ents. if ($action eq $SENDSTR) { open(OUT,">>$xls_file") || print "could not open $xls_file" ; } foreach ($query->param) { $in{$_} = $query->param($_); if ($_=~/^c_/) { $check{$_}="CHECKED" } #checkbox if ($_=~/^r_/) { $check{$_.$in{$_}}="CHECKED" } #radio if ($_=~/^s_/) { $check{$_.$in{$_}}="SELECTED" } #Select if ($action eq $SENDSTR) { $in{$_}=~s/\r\n/ /g; if ($_ !~/action|lang/) { # don't print these fields to X +LS file print OUT "$in{$_}\t"; } } $in{$_}=~s/\r\n/<br>/g || $in{$_}=~s/<br>/\n/g; $in{$_}=~s/"/&quot;/g; $in{$_}=~s/'/&rsquo;/g; $in{$_}=~s/\$/&\#36;/g; } # end foreach if ($action eq $SENDSTR) { print OUT "$today\t"; print OUT "\n"; close(OUT); } }

      I have no idea what I was thinking when I wrote the first part of that post. Like I said in the second half, unchecked checkboxes are not in the list of params. As per the HTML spec, they are not sent by the client to the server. You need to loop over the fields you want to output, not over the params

      my @fields = qw( ... c_... c_... c_... ... ); foreach (@fields) { $in{$_} = $query->param($_); if (/^c_/ && defined($in{$_})) { $check{$_} = "CHECKED"; } ... }