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!

validate radio boxes using javascript

Status
Not open for further replies.

CF808

Programmer
Mar 29, 2000
4
US
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=&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 ( var i=1; i<=<CFOUTPUT>#Get_Questions.RecordCount#</CFOUTPUT>; i++){

if(document.form.answer.type == &quot;radio&quot;)
{
document.form.answeri.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;>
</CFIF>
</BODY>
</HTML>
 
You need to give your <form> tag a name attribute so JS can reference it. Try <form name=&quot;f1&quot; ...> and then change any references to &quot;document.form.&quot; to &quot;document.f1.&quot; like this:

document.form.answeri.checked=false;
becomes...
document.f1.answeri.checked=false;

Let me know if you still have problems.
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top