Javascript Help, Quiz Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Javascript Help, Quiz Script

Post 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!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

do you know how to make it postable?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well, it would help if you changed the target from HTML to PHP.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

what target?
Post Reply