I have been trying to find a way to validate radio boxes on a test form, to insure that all questions have been answered. I get the Javascript error that "document.form has no properties. HELP!!
here is the bottom half of my form:
<CFSET #new#=0>
<CFSET starttime="#curdate#">
<CFQUERY NAME="Method_Used" DATASOURCE="#dsn#">
SELECT *
FROM Methods
WHERE active=1
</CFQUERY>
<CFQUERY NAME="Get_Module" DATASOURCE="#dsn#">
SELECT *
FROM Modules
WHERE modid=#modid# AND active=1
</CFQUERY>
<CFQUERY NAME="Get_Questions" DATASOURCE="#dsn#">
SELECT *
FROM Quest
WHERE modid=#Get_Module.modid#
ORDER BY modid,qid
</CFQUERY>
<HTML>
<HEAD> <TITLE>TESTING METHOD 1 PAGE</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// function to ensure all form fields are filled out.
function CheckValues()
{
// loop through each record.
for ( var i=1; i<=<CFOUTPUT>#Get_Questions.RecordCount#</CFOUTPUT>; i++){
if(document.form.answer.type == "radio"
{
document.form.answeri.checked=false;
alert("You must enter an answer for question number "+<CFOUTPUT>#Get_Questions.qnum#</CFOUTPUT>+"."
return false;
break;
}
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="Beige">
<BR>
<TABLE ALIGN="center" BORDER="0">
<TR>
<TD COLSPAN="2" ALIGN="center">
<FONT SIZE="+2"COLOR="DarkGreen">
<B>Welcome to Testing for
<CFOUTPUT>#Get_Module.module#</FONT></CFOUTPUT></B>
</TD>
</TR>
<TR>
<TD COLSPAN="2">
<FONT FACE="Arial" SIZE="2"COLOR="DarkGreen">
<B>
<CFOUTPUT>#Method_Used.Instruction#</CFOUTPUT>
<BR><DIV ALIGN="center">You may begin testing now!</DIV></FONT></B>
</TD>
</TR>
</TABLE>
<HR COLOR="DarkGreen" WIDTH="90%"SIZE="7">
<!--- QUESTIONS --->
<FORM ACTION = "METHOD01.cfm?NEW=1&<CFOUTPUT>modid=#modid#</CFOUTPUT>" METHOD = "post" onSubmit = "return CheckValues()">
<CFOUTPUT>
<INPUT TYPE = "hidden" NAME = "NumRecords" VALUE = "#Get_Questions.RecordCount#">
</CFOUTPUT>
<TABLE ALIGN="center" BORDER="1" WIDTH="90%">
<TR>
<CFOUTPUT QUERY="Get_Questions" GROUP="qnum">
<TD ALIGN="right" WIDTH="5%"><B>#qnum#</B>.&nbsp;&nbsp;</TD>
<TD ALIGN="left" WIDTH="65%">
<FONT FACE="Arial" SIZE="2"COLOR="DarkGreen">
<B>#QUEST#</B></FONT><BR>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="A">
<B>A.&nbsp;&nbsp;#a#</B><BR>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="B">
<B>B.&nbsp;&nbsp;#b#</B><BR>
<CFIF #c# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="C">
<B>C.&nbsp;&nbsp;#c#</B><BR>
</CFIF>
<CFIF #d# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="D">
<B>D.&nbsp;&nbsp;#d#</B><BR>
</CFIF>
<CFIF #e# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="E">
<B>E.&nbsp;&nbsp;#e#</B><BR>
</CFIF>
</TD>
<TD WIDTH="30%">
&nbsp;
</TD>
</TR>
<INPUT TYPE = "hidden" NAME = "userID#CurrentRow#" VALUE = "#Session.User_ID#">
<INPUT TYPE = "hidden" NAME = "qnum#CurrentRow#" VALUE = "#qnum#">
<INPUT TYPE = "hidden" NAME = "modid#CurrentRow#" VALUE = "#modid#">
<INPUT TYPE = "hidden" NAME = "methid#CurrentRow#" VALUE = "#Method_Used.methid#">
<INPUT TYPE = "hidden" NAME = "StartTime#CurrentRow#" VALUE = "#StartTime#">
<INPUT TYPE = "hidden" NAME = "explanation#CurrentRow#" VALUE = "#explanation#">
<!--- CREATE ENDTIME WHEN ADDING RECORDS TO TABLE --->
</CFOUTPUT>
<TR>
<TD COLSPAN="3" ALIGN="center">
<INPUT TYPE="SUBMIT" VALUE="End Test">
</TD>
</TR>
</TABLE>
</FORM>
<HR COLOR="DarkGreen" WIDTH="90%"SIZE="7">
</CFIF>
</BODY>
</HTML>
here is the bottom half of my form:
<CFSET #new#=0>
<CFSET starttime="#curdate#">
<CFQUERY NAME="Method_Used" DATASOURCE="#dsn#">
SELECT *
FROM Methods
WHERE active=1
</CFQUERY>
<CFQUERY NAME="Get_Module" DATASOURCE="#dsn#">
SELECT *
FROM Modules
WHERE modid=#modid# AND active=1
</CFQUERY>
<CFQUERY NAME="Get_Questions" DATASOURCE="#dsn#">
SELECT *
FROM Quest
WHERE modid=#Get_Module.modid#
ORDER BY modid,qid
</CFQUERY>
<HTML>
<HEAD> <TITLE>TESTING METHOD 1 PAGE</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// function to ensure all form fields are filled out.
function CheckValues()
{
// loop through each record.
for ( var i=1; i<=<CFOUTPUT>#Get_Questions.RecordCount#</CFOUTPUT>; i++){
if(document.form.answer.type == "radio"
{
document.form.answeri.checked=false;
alert("You must enter an answer for question number "+<CFOUTPUT>#Get_Questions.qnum#</CFOUTPUT>+"."
return false;
break;
}
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="Beige">
<BR>
<TABLE ALIGN="center" BORDER="0">
<TR>
<TD COLSPAN="2" ALIGN="center">
<FONT SIZE="+2"COLOR="DarkGreen">
<B>Welcome to Testing for
<CFOUTPUT>#Get_Module.module#</FONT></CFOUTPUT></B>
</TD>
</TR>
<TR>
<TD COLSPAN="2">
<FONT FACE="Arial" SIZE="2"COLOR="DarkGreen">
<B>
<CFOUTPUT>#Method_Used.Instruction#</CFOUTPUT>
<BR><DIV ALIGN="center">You may begin testing now!</DIV></FONT></B>
</TD>
</TR>
</TABLE>
<HR COLOR="DarkGreen" WIDTH="90%"SIZE="7">
<!--- QUESTIONS --->
<FORM ACTION = "METHOD01.cfm?NEW=1&<CFOUTPUT>modid=#modid#</CFOUTPUT>" METHOD = "post" onSubmit = "return CheckValues()">
<CFOUTPUT>
<INPUT TYPE = "hidden" NAME = "NumRecords" VALUE = "#Get_Questions.RecordCount#">
</CFOUTPUT>
<TABLE ALIGN="center" BORDER="1" WIDTH="90%">
<TR>
<CFOUTPUT QUERY="Get_Questions" GROUP="qnum">
<TD ALIGN="right" WIDTH="5%"><B>#qnum#</B>.&nbsp;&nbsp;</TD>
<TD ALIGN="left" WIDTH="65%">
<FONT FACE="Arial" SIZE="2"COLOR="DarkGreen">
<B>#QUEST#</B></FONT><BR>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="A">
<B>A.&nbsp;&nbsp;#a#</B><BR>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="B">
<B>B.&nbsp;&nbsp;#b#</B><BR>
<CFIF #c# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="C">
<B>C.&nbsp;&nbsp;#c#</B><BR>
</CFIF>
<CFIF #d# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="D">
<B>D.&nbsp;&nbsp;#d#</B><BR>
</CFIF>
<CFIF #e# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#" VALUE="E">
<B>E.&nbsp;&nbsp;#e#</B><BR>
</CFIF>
</TD>
<TD WIDTH="30%">
&nbsp;
</TD>
</TR>
<INPUT TYPE = "hidden" NAME = "userID#CurrentRow#" VALUE = "#Session.User_ID#">
<INPUT TYPE = "hidden" NAME = "qnum#CurrentRow#" VALUE = "#qnum#">
<INPUT TYPE = "hidden" NAME = "modid#CurrentRow#" VALUE = "#modid#">
<INPUT TYPE = "hidden" NAME = "methid#CurrentRow#" VALUE = "#Method_Used.methid#">
<INPUT TYPE = "hidden" NAME = "StartTime#CurrentRow#" VALUE = "#StartTime#">
<INPUT TYPE = "hidden" NAME = "explanation#CurrentRow#" VALUE = "#explanation#">
<!--- CREATE ENDTIME WHEN ADDING RECORDS TO TABLE --->
</CFOUTPUT>
<TR>
<TD COLSPAN="3" ALIGN="center">
<INPUT TYPE="SUBMIT" VALUE="End Test">
</TD>
</TR>
</TABLE>
</FORM>
<HR COLOR="DarkGreen" WIDTH="90%"SIZE="7">
</CFIF>
</BODY>
</HTML>