Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking to see if radio buttons have been selected

Status
Not open for further replies.

CF808

Programmer
Mar 29, 2000
4
US
I am trying to validate selestions for test questions. In my form the questions may have up to five choices a-e. The actual field is referenced as answer#currentrow#. I want to make sure all of the questions have been answered. Everytime I try to run my form is submitted i get the JAVASCRIPT ERROR that document.form has no properties.

PLEASE HELP, ALOHA!

<!--- GET TESTING INPUT AND VALUES --->
<CFSET #new#=0>
<CFSET starttime=&quot;#curdate#&quot;>

<CFQUERY NAME=&quot;Method_Used&quot; DATASOURCE=&quot;#dsn#&quot;>
SELECT *
FROM Methods
WHERE active=1
</CFQUERY>

<CFQUERY NAME=&quot;Get_Module&quot; DATASOURCE=&quot;#dsn#&quot;>
SELECT *
FROM Modules
WHERE modid=#modid# AND active=1
</CFQUERY>

<CFQUERY NAME=&quot;Get_Questions&quot; DATASOURCE=&quot;#dsn#&quot;>
SELECT *
FROM Quest
WHERE modid=#Get_Module.modid#
ORDER BY modid,qid
</CFQUERY>

<HTML>
<HEAD> <TITLE>TESTING METHOD 1 PAGE</TITLE>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

// 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 == &quot;radio&quot;)
{
document.form.answer.checked=false;
alert(&quot;You must enter an answer for question number &quot;+<CFOUTPUT>#Get_Questions.qnum#</CFOUTPUT>+&quot;.&quot;);
return false;
break;
}
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR=&quot;Beige&quot;>
<BR>
<TABLE ALIGN=&quot;center&quot; BORDER=&quot;0&quot;>
<TR>
<TD COLSPAN=&quot;2&quot; ALIGN=&quot;center&quot;>
<FONT SIZE=&quot;+2&quot;COLOR=&quot;DarkGreen&quot;>
<B>Welcome to Testing for
<CFOUTPUT>#Get_Module.module#</FONT></CFOUTPUT></B>
</TD>
</TR>
<TR>
<TD COLSPAN=&quot;2&quot;>
<FONT FACE=&quot;Arial&quot; SIZE=&quot;2&quot;COLOR=&quot;DarkGreen&quot;>
<B>
<CFOUTPUT>#Method_Used.Instruction#</CFOUTPUT>
<BR><DIV ALIGN=&quot;center&quot;>You may begin testing now!</DIV></FONT></B>
</TD>
</TR>
</TABLE>
<HR COLOR=&quot;DarkGreen&quot; WIDTH=&quot;90%&quot;SIZE=&quot;7&quot;>

<!--- QUESTIONS --->
<FORM ACTION = &quot;METHOD01.cfm?NEW=1&amp;<CFOUTPUT>modid=#modid#</CFOUTPUT>&quot; METHOD = &quot;post&quot; onSubmit = &quot;return CheckValues()&quot;>

<CFOUTPUT>
<INPUT TYPE = &quot;hidden&quot; NAME = &quot;NumRecords&quot; VALUE = &quot;#Get_Questions.RecordCount#&quot;>
</CFOUTPUT>
<TABLE ALIGN=&quot;center&quot; BORDER=&quot;1&quot; WIDTH=&quot;90%&quot;>
<TR>

<CFOUTPUT QUERY=&quot;Get_Questions&quot; GROUP=&quot;qnum&quot;>

<TD ALIGN=&quot;right&quot; WIDTH=&quot;5%&quot;><B>#qnum#</B>.&amp;nbsp;&amp;nbsp;</TD>
<TD ALIGN=&quot;left&quot; WIDTH=&quot;65%&quot;>
<FONT FACE=&quot;Arial&quot; SIZE=&quot;2&quot;COLOR=&quot;DarkGreen&quot;>
<B>#QUEST#</B></FONT><BR>

<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot; VALUE=&quot;A&quot;>
<B>A.&amp;nbsp;&amp;nbsp;#a#</B><BR>

<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot; VALUE=&quot;B&quot;>
<B>B.&amp;nbsp;&amp;nbsp;#b#</B><BR>

<CFIF #c# IS &quot;&quot;>
<CFELSE>
<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot; VALUE=&quot;C&quot;>
<B>C.&amp;nbsp;&amp;nbsp;#c#</B><BR>
</CFIF>

<CFIF #d# IS &quot;&quot;>
<CFELSE>
<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot; VALUE=&quot;D&quot;>
<B>D.&amp;nbsp;&amp;nbsp;#d#</B><BR>
</CFIF>

<CFIF #e# IS &quot;&quot;>
<CFELSE>
<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot; VALUE=&quot;E&quot;>
<B>E.&amp;nbsp;&amp;nbsp;#e#</B><BR>
</CFIF>

</TD>
<TD WIDTH=&quot;30%&quot;>
&amp;nbsp;
</TD>
</TR>
<INPUT TYPE = &quot;hidden&quot; NAME = &quot;userID#CurrentRow#&quot; VALUE = &quot;#Session.User_ID#&quot;>
<INPUT TYPE = &quot;hidden&quot; NAME = &quot;qnum#CurrentRow#&quot; VALUE = &quot;#qnum#&quot;>
<INPUT TYPE = &quot;hidden&quot; NAME = &quot;modid#CurrentRow#&quot; VALUE = &quot;#modid#&quot;>
<INPUT TYPE = &quot;hidden&quot; NAME = &quot;methid#CurrentRow#&quot; VALUE = &quot;#Method_Used.methid#&quot;>
<INPUT TYPE = &quot;hidden&quot; NAME = &quot;StartTime#CurrentRow#&quot; VALUE = &quot;#StartTime#&quot;>
<INPUT TYPE = &quot;hidden&quot; NAME = &quot;explanation#CurrentRow#&quot; VALUE = &quot;#explanation#&quot;>
<!--- CREATE ENDTIME WHEN ADDING RECORDS TO TABLE --->
</CFOUTPUT>
<TR>
<TD COLSPAN=&quot;3&quot; ALIGN=&quot;center&quot;>
<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;End Test&quot;>
</TD>
</TR>
</TABLE>
</FORM>
<HR COLOR=&quot;DarkGreen&quot; WIDTH=&quot;90%&quot;SIZE=&quot;7&quot;>
</BODY>
</HTML>
 
This might be alittle late but try using <cfform> and use <cfinput name=&quot;nnn&quot; required=&quot;yes&quot; message=&quot;Please fill in value for the name&quot;> The only dumb questions are the ones that are never asked
 
CF808,

if you want to access a form without a name, use this syntax:

document.forms[0]

so your code should be:
if(document.forms[0].answer[index].type == &quot;radio&quot;)

hope this helps.
======================================

if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top