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!

How to Check for radio button (has it been ckecked?)

Status
Not open for further replies.

CF808

Programmer
Mar 29, 2000
4
US
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=&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;>
<!--- 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><B>#qnum#</B>.&amp;nbsp;&amp;nbsp;</TD>
<TD>#QUEST#<BR>
<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot;
VALUE=&quot;A&quot;>A.&amp;nbsp;&amp;nbsp;#a#<BR>
<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot;
VALUE=&quot;B&quot;>B.&amp;nbsp;&amp;nbsp;#b#<BR>
<CFIF #c# IS &quot;&quot;>
<CFELSE>
<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot;
VALUE=&quot;C&quot;>C.&amp;nbsp;&amp;nbsp;#c#<BR>
</CFIF>
<CFIF #d# IS &quot;&quot;>
<CFELSE>
<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot;
VALUE=&quot;D&quot;>D.&amp;nbsp;&amp;nbsp;#d#<BR>
</CFIF>
<CFIF #e# IS &quot;&quot;>
<CFELSE>
<INPUT TYPE=&quot;Radio&quot; NAME = &quot;answer#CurrentRow#&quot;
VALUE=&quot;E&quot;>E.&amp;nbsp;&amp;nbsp;#e#<BR>
</CFIF>
</TD>
</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>
</BODY>
</HTML>
 
faq216-342

I would like to edit it - but this facility is not available. Instead of using strings. I would send the actual object to the function - to save mucking around with evals etc. &quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top