EastIndian
Technical User
I am trying to ensure that a radio option is selected before the form is processed. It looks like, from the error message that I am getting, that my validation is not working. Included is the portion of my page containing the validation for the radio option. The error message I am receiving when I submit the form without selecting one of the radio options pertains to the radio field in the processing page, saying it does not exist, which makes sence since nothing has been checked. Anyone have any hints form me?
<!--- Get the options for the question... --->
<CFQUERY NAME="getOptions" DATASOURCE="#S_datasource#">
SELECT optionID, questionOoption
FROM options
WHERE surveyID = #listOnesValue#
</CFQUERY>
<CFSET survey = listOnesValue>
</CFIF>
<HTML>
<HEAD>
<TITLE>Validation Testing</TITLE>
<!---
<SCRIPT LANGUAGE="JavaScript">
// function to ensure radio is checked.
function CheckValues()
{
// loop through each record.
for ( var i=1; i<=<CFOUTPUT>#GetOptions.RecordCount#</CFOUTPUT>; i++){
if(document.survey.answer.type == "radio"
{
document.survey.answeri.checked=false;
alert("You have not selected an answer."
return false;
break;
}
}
}
</SCRIPT>
--->
</HEAD>
<form name="survey" action="<cfoutput>#surveyResults#</cfoutput>" method="Post" onSubmit="return CheckValues()">
<table cellspacing=0 cellpadding=0 border=0>
<tr><td>
<table width="<cfoutput>#S_width#</cfoutput>" border=<cfoutput>"#S_border#" </cfoutput>
cellspacing=0 cellpadding=5>
<tr>
<td bgcolor="<cfoutput>###S_headerColor#</cfoutput>">
<cfoutput><font face="#S_headerFont#" size="-1" color="#S_headerFontColor#"></cfoutput>
<cfoutput query="getQuestion">
<strong>#question#</strong><br>
</cfoutput>
</font>
</td>
</tr>
<tr>
<td bgcolor="<cfoutput>###S_bodyColor#</cfoutput>">
<cfoutput><font face="#S_bodyFont#" size="-1" color="#S_bodyFontColor#"></cfoutput>
<CFSET myCount = "0">
<cfoutput query="getOptions">
<input type="radio" value="#optionID#" name="radio">#questionOption#<br>
<CFSET myCount = myCount + 1>
</cfoutput>
<cfoutput>
<input type="hidden" name="survey" value="#survey#">
</cfoutput>
<input type="submit" value="Submit"></form>
</font>
</td></tr></table>
<!--- Get the options for the question... --->
<CFQUERY NAME="getOptions" DATASOURCE="#S_datasource#">
SELECT optionID, questionOoption
FROM options
WHERE surveyID = #listOnesValue#
</CFQUERY>
<CFSET survey = listOnesValue>
</CFIF>
<HTML>
<HEAD>
<TITLE>Validation Testing</TITLE>
<!---
<SCRIPT LANGUAGE="JavaScript">
// function to ensure radio is checked.
function CheckValues()
{
// loop through each record.
for ( var i=1; i<=<CFOUTPUT>#GetOptions.RecordCount#</CFOUTPUT>; i++){
if(document.survey.answer.type == "radio"
{
document.survey.answeri.checked=false;
alert("You have not selected an answer."
return false;
break;
}
}
}
</SCRIPT>
--->
</HEAD>
<form name="survey" action="<cfoutput>#surveyResults#</cfoutput>" method="Post" onSubmit="return CheckValues()">
<table cellspacing=0 cellpadding=0 border=0>
<tr><td>
<table width="<cfoutput>#S_width#</cfoutput>" border=<cfoutput>"#S_border#" </cfoutput>
cellspacing=0 cellpadding=5>
<tr>
<td bgcolor="<cfoutput>###S_headerColor#</cfoutput>">
<cfoutput><font face="#S_headerFont#" size="-1" color="#S_headerFontColor#"></cfoutput>
<cfoutput query="getQuestion">
<strong>#question#</strong><br>
</cfoutput>
</font>
</td>
</tr>
<tr>
<td bgcolor="<cfoutput>###S_bodyColor#</cfoutput>">
<cfoutput><font face="#S_bodyFont#" size="-1" color="#S_bodyFontColor#"></cfoutput>
<CFSET myCount = "0">
<cfoutput query="getOptions">
<input type="radio" value="#optionID#" name="radio">#questionOption#<br>
<CFSET myCount = myCount + 1>
</cfoutput>
<cfoutput>
<input type="hidden" name="survey" value="#survey#">
</cfoutput>
<input type="submit" value="Submit"></form>
</font>
</td></tr></table>