Page 1 of 1

Javascript Help, Quiz Script

Posted: Wed Jan 18, 2006 3:49 pm
by nickman013
Hello,

I am making a online quiz for somebody.

My code is

Code: Select all

<html><font face=garamond><b>
<body bgcolor=black>
<title>Mr. Farris' Online Test </title>
<head>
<SCRIPT language="JavaScript" type="text/javascript">

function checkAnswer(quizForm,
                     theAnswer,
                     urlRight,
                     urlWrong)
{
  var s = "?";

  // go through the "current choices"
  // to find the selected choice.
  // radio boxes pointing to choices
  // must be named "cc"
  // change if necessary
  //
  var i = 0;
  for(;i<quizForm.elements.length;i++)
  {
    if(("cc" ==
        quizForm.elements[i].name) &&
       (quizForm.elements[i].checked))
    {
      s = quizForm.elements[i].value;
    }
  }

  // no choice was selected
  //
  if("?" == s)
  {
    alert("Please make a selection.");
    return false;
  }

  // check if we have the correct
  // choice selected
  //
  if(s == theAnswer)
  {
    alert("'"+s+"' is correct!");
    if(urlRight)
    {
    document.location.href = urlRight;
    }
  }
  else
  {
    alert("'"+s+"' is incorrect.");
    if( urlWrong )
    {
    document.location.href = urlWrong;
    }
  }

  // return "false" to indicate not to
  // submit the form.
  // change this to "true" if the form
  // "action" is valid,
  // i.e. points to a valid CGI script
  //
  return false;
}
</SCRIPT>
</head>
<font size=5 color=#DAA520><center><b><u>
Mr. Farris' Online Test</b></center></font></u>
<div align=right><font size=2 color=white><a onClick="javascript:window.close();">[exit]</a>
<hr>
<br><br><br><br>
</div><div align=center><TABLE WIDTH=600 CELLPADDING=8 CELLSPACING=0 border=1 bordercolor=black BGCOLOR="ivory">
      <TR><TD bgcolor=#DAA520> &nbsp; 
<FONT FACE="garamonda" SIZE=+0 COLOR="black">
<B>Question #1
</B></FONT>
</TD></TR>
<TR>
<FORM method=POST onSubmit="return checkAnswer(this,'B');">
        <TD valign="top"> 
          <TABLE WIDTH=100% CELLPADDING=10 CELLSPACING=0 BORDER=0 BGCOLOR="#DAA520">
            <TR>
              <TD height="23" valign="top"> 
			<b>  Is Mr. Farris Cool?</b><BR>
                <BR>

             <TABLE  BORDER=0 CELLSPACING=0 CELLPADDING=0>
                  <TR> 
                    <TD VALIGN=top>
                      <INPUT TYPE="Radio" NAME="cc" VALUE="A">
                    </TD>
                    <TD VALIGN=top>&nbsp;1.&nbsp;</TD>
                    <TD VALIGN=top> 
                      
                      no!
                      
                      <BR>
                      <FONT SIZE=-2> <BR>
                      </FONT></TD>
                  </TR>
                  <TR> 
                    <TD VALIGN=top>
                      <INPUT TYPE="Radio" NAME="cc" VALUE="B">
                    </TD>
                    <TD VALIGN=top>&nbsp;2.&nbsp;</TD>
                    <TD VALIGN=top> 
                      
                      mybee
                      
                      <BR>
                      <FONT SIZE=-2> <BR>
                      </FONT></TD>
                  </TR>
                  <TR> 
                    <TD VALIGN=top>
                      <INPUT TYPE="Radio" NAME="cc" VALUE="C">
                    </TD>
                    <TD VALIGN=top>&nbsp;3.&nbsp;</TD>
                    <TD VALIGN=top> 
                      
                      yeah
                      
                      <BR>
                      <FONT SIZE=-2> <BR>
                      </FONT></TD>
                  </TR>
                  
                  <TR> 
                    <TD VALIGN=top>
                      <INPUT TYPE="Radio" NAME="cc" VALUE="D">
                    </TD>
                    <TD VALIGN=top>&nbsp;4.&nbsp;</TD>
                    <TD VALIGN=top> 
                      
                     sometimes
                      
                      <BR>
                      <FONT SIZE=-2> <BR>
                      </FONT></TD>
                  </TR>
				  
                  
                </TABLE>


<CENTER><INPUT TYPE="submit" VALUE="Check Your Answer"></CENTER>
</TD></TR>
</TABLE>

</TD></TR>
</TABLE>
</div>
</form>

</head>
<body>
<form>
<BR><BR><BR><BR><BR><BR><BR><BR><BR>
I get and error when submitting,
The requested method POST is not allowed for the URL /farris/farris.htm.
I can not figure out what is wrong. Can You?

Thank You!!

Posted: Wed Jan 18, 2006 9:23 pm
by feyd
doesn't appear to have anything to do with your javascript, but more likely is because the file you've created doesn't map to a post-able file for the web server.

Posted: Sat Jan 21, 2006 3:46 pm
by nickman013
do you know how to make it postable?

Posted: Sat Jan 21, 2006 7:12 pm
by Ambush Commander
Well, it would help if you changed the target from HTML to PHP.

Posted: Sat Jan 21, 2006 9:09 pm
by nickman013
what target?