I basically learned Perl by altering existing scripts (yeah, not the best, I know). I need to generate multiple unique checkboxes in an HTML page, then see if any of them have been checked.

The whole little testing script is below. If I check for simple checkedness, ie, "if ($value)", nothing shows as checked. Likewise for "if ($value eq 'on')" (or any string, or number). If I try "if ($value == 'any damn string')" EVERTHING is on.

I suspect the problem is actually how I am getting the form parameters into the $form_data array, which is a piece of apparent magic from the original script I started with and seems to have worked fine for all the other field types in the actual real cgi program.

The script can be run from http://www.toukleyartgallery.com.au/cgi-bin/checktest.htm

#!/usr/bin/perl -w BEGIN { open (STDERR, ">test.err");} use CGI qw(:standard); use CGI::Carp qw/fatalsToBrowser/; $ENV{"PATH"} = ""; print "Content-type: text/html\n\n"; $query = new CGI; foreach $sparam ($query->param()) { $form_data{$sparam} = $query->param($sparam); } &check_test; sub check_test() { print qq~ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:/ +/www.w3.org/TR/html4/loose.dtd"> <html> <head> </head> <body> ~; print "<form name='form1' method='post' action='http://www.toukley +artgallery.com.au/cgi-bin/checktest.cgi'>\n"; for $i (1 .. 4) { for $j (1 .. 4) { if ($form_data{'box$i$j'} == "definitely not on") { print "<font color='#FF0000'>Box $i$j: $form_data{'bo +x$i$j'}</font> "; } else { print "Box $i$j: <input type='checkbox' name='box$i$j' +> " } } } print "\n<input type='submit' name='Submit' value='Submit'>\n</for +m>\n"; print "</body>\n</html>\n"; }

In reply to Trouble testing if on-the-fly generated checkboxes are checked by goldgryph

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.