[ back to toc ]

Creating a Test

Date: 2002/03/12 09:43

Q:
I'm creating a multiple choice and true and false test with radio buttons.
How do I go about having the cgi file grade it with the right
and wrong answers?

I can't get it to distinguish between the right and wrong answers. I think
maybe because the NAME attribute in the HTML file has the same
name for radio buttons and I don't know how to ask it to pull the correct
information for process.

If you need more information, please let me know and I don't mind the
delay as long as I can get a suggestion on what to try.

Thanks in advance for your help.
A:
The name of the radio button is the same, however the value is different.
You have to check the value of the returned radio button in the CGI
program to know which radio button was pressed.

Regards,
Peter
Q:
Please see http://www.visualstatic.com/radiotest.htm for an example.

My attempts are not working. I've tried several things with no luck and I
don't know how to check the value like you suggested. Could you be more
specific? Thanks Nancy.

CGI file:

#!/usr/bin/perl
require "cgi-lib.pl";
&ReadParse;
print &PrintHeader;
print "<html><body>";
if ($color3 eq "red")
{
print "<p>You are correct.</p>";
}
if ($color3 eq "orange")
{
print "<p>You are wrong.</p>";
}
if ($color3 eq "blue")
{
print "<p>You are wrong.</p>";
if ($color2==1)
{
print "<p>You are correct.</p>";
}
else
{
print "<p>You are wrong.</p>";
}
print "</body></html>";
#end of program

A:
Ok. I can see what you miss. The godd news is that you are almost correct.
The only mistake is that the result of the CGI input parsing is not put
directly into Perl variables but rather into the hash %in. Thus instead of

if ($color3 eq "red")

you have to write:

if ($in{'color3'} eq "red")

Regards,
Peter

[ back to toc ]