artificialg
07-20-2004, 04:39 AM
ok i have a cgi poll up at my website. you can check it out at http://www.artificialg.net the poll works fine, but i want the results to be displayed on the homepage instead of a separate page being loaded with the reuslts of the cgi poll. essentially, i want my homepage to reload once someone has voted and display the results of the poll where the poll question is before someone votes. does anyone know how i can accomplish this? javascript possibly? i've done some extensive searching on the internet, but couldn't find anything. thanks in advance.
edit: here is the cgi code in case it helps.
#!/usr/local/bin/perl
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
# Load the FORM variables
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
}
print "Content-type: text/html\n\n";
if(-e "poll.dat")
{
open(POLL, "poll.dat");
}
while(<POLL>)
{
push(@poll, $_);
}
close(POLL);
@lines = ("1");
foreach $each_line (@lines)
{
$this_line = "line" . $each_line;
$$this_line = $poll[$each_line-1];
chop($$this_line);
}
if($line1 eq " ")
{
$line1 = "0\t0\t0";
}
@line1_answers = split(/\t/, $line1);
if($FORM{'QUESTION'} eq "yes")
{
$line1_answers[0]++;
}
elsif($FORM{'QUESTION'} eq "no")
{
$line1_answers[1]++;
}
open(POLL, ">poll.dat");
print POLL "$line1_answers[0]\t$line1_answers[1]\n";
close(POLL);
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>artificialg.net</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=white>\n";
print "<font face=arial color=#0000bb size=1>\n";
print "do you recycle?<BR><BR>\n";
print "<font face=arial color=#0000bb size=1>\n";
print "yes ";
print " \n";
print $line1_answers[0] / ($line1_answers[0] + $line1_answers[1])*100;
print " %";
print "<BR><BR>\n";
print "no ";
print " \n";
print $line1_answers[1] / ($line1_answers[0] + $line1_answers[1])*100;
print " %";
print "</TD>";
print "</BODY>\n";
print "</HTML>\n";
edit: here is the cgi code in case it helps.
#!/usr/local/bin/perl
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
# Load the FORM variables
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
}
print "Content-type: text/html\n\n";
if(-e "poll.dat")
{
open(POLL, "poll.dat");
}
while(<POLL>)
{
push(@poll, $_);
}
close(POLL);
@lines = ("1");
foreach $each_line (@lines)
{
$this_line = "line" . $each_line;
$$this_line = $poll[$each_line-1];
chop($$this_line);
}
if($line1 eq " ")
{
$line1 = "0\t0\t0";
}
@line1_answers = split(/\t/, $line1);
if($FORM{'QUESTION'} eq "yes")
{
$line1_answers[0]++;
}
elsif($FORM{'QUESTION'} eq "no")
{
$line1_answers[1]++;
}
open(POLL, ">poll.dat");
print POLL "$line1_answers[0]\t$line1_answers[1]\n";
close(POLL);
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>artificialg.net</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=white>\n";
print "<font face=arial color=#0000bb size=1>\n";
print "do you recycle?<BR><BR>\n";
print "<font face=arial color=#0000bb size=1>\n";
print "yes ";
print " \n";
print $line1_answers[0] / ($line1_answers[0] + $line1_answers[1])*100;
print " %";
print "<BR><BR>\n";
print "no ";
print " \n";
print $line1_answers[1] / ($line1_answers[0] + $line1_answers[1])*100;
print " %";
print "</TD>";
print "</BODY>\n";
print "</HTML>\n";