goldgryph has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble testing if on-the-fly generated checkboxes are checked
by Your Mother (Archbishop) on Jun 06, 2018 at 04:46 UTC | |
|
Re: Trouble testing if on-the-fly generated checkboxes are checked
by bliako (Abbot) on Jun 06, 2018 at 09:49 UTC | |
|
Re: Trouble testing if on-the-fly generated checkboxes are checked
by goldgryph (Initiate) on Jun 06, 2018 at 02:55 UTC | |
by poj (Abbot) on Jun 06, 2018 at 06:46 UTC | |
|
Re: Trouble testing if on-the-fly generated checkboxes are checked
by goldgryph (Initiate) on Jun 06, 2018 at 07:26 UTC |