This is my second attempt. I have a page with test questions. I want to ensure that each question has been answered (each radio button must be selected). In my form the questions may have up to five choices a-e.
Everytime I try to run my form is submitted i get the JAVASCRIPT ERROR that DOCUMENT.FORM.FIELD IS NULL OR NOT AN OBJECT.
PLEASE HELP, THANK YOU!
<!--- GET TESTING INPUT AND VALUES --->
<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 (i=1; i<=<CFOUTPUT>#Get_Questions.RecordCount#</CFOUTPUT>; i++){
if(document.form.answer.type == "radio"
{
document.form.answer.checked=false;
alert("You must enter an answer for question number "+<CFOUTPUT>#Get_Questions.qnum#</CFOUTPUT>+"."
return false;
break;
}
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="Beige">
<!--- 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><B>#qnum#</B>.&nbsp;&nbsp;</TD>
<TD>#QUEST#<BR>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="A">A.&nbsp;&nbsp;#a#<BR>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="B">B.&nbsp;&nbsp;#b#<BR>
<CFIF #c# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="C">C.&nbsp;&nbsp;#c#<BR>
</CFIF>
<CFIF #d# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="D">D.&nbsp;&nbsp;#d#<BR>
</CFIF>
<CFIF #e# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="E">E.&nbsp;&nbsp;#e#<BR>
</CFIF>
</TD>
</CFOUTPUT>
<TR>
<TD COLSPAN="3" ALIGN="center">
<INPUT TYPE="SUBMIT" VALUE="End Test">
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Everytime I try to run my form is submitted i get the JAVASCRIPT ERROR that DOCUMENT.FORM.FIELD IS NULL OR NOT AN OBJECT.
PLEASE HELP, THANK YOU!
<!--- GET TESTING INPUT AND VALUES --->
<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 (i=1; i<=<CFOUTPUT>#Get_Questions.RecordCount#</CFOUTPUT>; i++){
if(document.form.answer.type == "radio"
{
document.form.answer.checked=false;
alert("You must enter an answer for question number "+<CFOUTPUT>#Get_Questions.qnum#</CFOUTPUT>+"."
return false;
break;
}
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="Beige">
<!--- 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><B>#qnum#</B>.&nbsp;&nbsp;</TD>
<TD>#QUEST#<BR>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="A">A.&nbsp;&nbsp;#a#<BR>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="B">B.&nbsp;&nbsp;#b#<BR>
<CFIF #c# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="C">C.&nbsp;&nbsp;#c#<BR>
</CFIF>
<CFIF #d# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="D">D.&nbsp;&nbsp;#d#<BR>
</CFIF>
<CFIF #e# IS "">
<CFELSE>
<INPUT TYPE="Radio" NAME = "answer#CurrentRow#"
VALUE="E">E.&nbsp;&nbsp;#e#<BR>
</CFIF>
</TD>
</CFOUTPUT>
<TR>
<TD COLSPAN="3" ALIGN="center">
<INPUT TYPE="SUBMIT" VALUE="End Test">
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>