Gossamer Forum
Home : General : Perl Programming :

Check box form/script

Quote Reply
Check box form/script
Am trying to create a form or cgi that will have the following:

checkbox 1 value = image 1
checkbox 2 value = image 2
checkbox 3 value = image 3
checkbox 4 value = image 4

and if checkbox 1 and 3 are checked, it will only display images # 1 & 3 on the results page.. tried to use java, but it's too much of a headache
Can anyone point me in the right direction??
Thanks,

Just a followup, here is what I'm trying to use...

Code:

<form method="post" action="/cgi-bin/test.pl">
<b>Check Your Favorite Pass Times:</b><br>
<input type="checkbox" name="a" value="<img src='/images/image1.gif'>"><img src="/images/image1.gif"><br>
<input type="checkbox" name="a" value="<img src='/images/image2.gif'>"><img src="/images/image2.gif"><br>
<input type="checkbox" name="a" value="<img src='/images/image3.gif'>"><img src="/images/image3.gif"><br>
<input type="checkbox" name="a" value="<img src='/images/image4.gif'>"><img src="/images/image4.gif"><br>
<input type="checkbox" name="a" value="<img src='/images/image5.gif'>"><img src="/images/image5.gif"><br>
<input type="checkbox" name="a" value="<img src='/images/image6.gif'>"><img src="/images/image6.gif"><br>
<input type="submit" value="Submit"><br>
</form>







#!/usr/bin/perl
#test.pl
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
$buffer =~ tr/+/ /;
$buffer =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$buffer =~ s/<!--(.|\n)*-->/ /g;
$buffer =~ tr/\\|[|]|<|!|"|$|{|}|*|#|'|>|||;|%/ /;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}
print "Content-type: text/html\n\n";
print <<End_of_Body;
<html>
<head><title>test</title>
</head>
<body>
<p>Awards:</p>
End_of_Body
while (($key,$value)= each(%formdata)){
print <<End_of_Loop;
<p>$value.</p>
<br>
End_of_Loop
}
print <<End_of_Document;
<p>End of Awards</p>
</body>
</html>
End_of_Document

</not a clue>

Last edited by:

Dinky: Oct 31, 2004, 3:48 PM
Quote Reply
Re: [Dinky] Check box form/script In reply to
it's only returning an out put of "img src", and not pulling up the images??
Unimpressed Unimpressed Unimpressed

</not a clue>
Quote Reply
Re: [Dinky] Check box form/script In reply to
Could you just use if/then statements? How many images are you looking at?

Here's what I'd do...
<INPUT TYPE="checkbox" NAME="a" VALUE="1">Image A
<INPUT TYPE="checkbox" NAME="b" VALUE="1">Image B
<INPUT TYPE="checkbox" NAME="c" VALUE="1">Image C

Then instead of doing a Loop (which is kinda cool) I'd just do if/then's

if ($a) {print qq|<IMG SRC="./images/a.gif">|;}
if ($b) {print qq|<IMG SRC="./images/b.gif">|;}
if ($c) {print qq|<IMG SRC="./images/c.gif">|;}