Hello,
I have a radio button validation script that should display an error message if no button is selected. It displays the error correctly when the form is submitted without a button being checked, but it also displays when the button is checked. Can someone look this over and let me know what is wrong?
Thanks!
---------------------------------------------------------------------------------------------------
The Script:
<Script Language="Javascript">
<!-- Begin
function checkRadios() {
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if(el.type == "radio" {
var radiogroup = el[el.name]; // get the whole set of radio buttons.
var itemchecked = false;
for(var j = 0 ; j < radiogroup.length ; ++j) {
if(radiogroup[j].checked) {
itemchecked = true;
break;
}
}
if(!itemchecked) {
alert("Please choose a record to commit this action on."
if(el.focus)
el.focus();
return false;
}
}
}
return true;
}
// End -->
</SCRIPT>
---------------------------------------------------------------------------------------------------
The Form:
<form action="pendingorders_RecordAction.cfm" method="post" name="menu" onsubmit="return checkRadios(this);">
<p align="left">
<INPUT type="submit" name="btnView_Delete" value="Cancel Order">
<INPUT type="submit" name="btn_View_Bill" value="View Order">
<input type="submit" name="btn_Edit_Bill" value="Edit Order">
<input type="submit" name="btnView_MainMenu" value="Return to Main Menu">
<cfoutput><input type="hidden" name="ID" value="#URL.ID#"</cfoutput>
</p>
<table border=0 cellpadding=3 cellspacing=0 size="600">
<tr>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF"></font></b></TD>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Order ID No:</font></b></TD>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Event Date:</font></b></TD>
<TD bgcolor="#000000"><B><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Date of Order:</font></B></TD>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Total Order Cost:</font></b></TD>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Select Record:</font></b></TD>
</tr>
<cfparam name="startrow" default="1">
<cfparam name="maxrows" default="10">
<cfoutput query="selectordersub" maxrows="#maxrows#" startrow="#startrow#">
<TR bgcolor="###Iif(((CurrentRow MOD 2) is 0),de('FFA8A8'),de('FFFFFF'))#">
<TD><font size="2" face="Arial, Helvetica, sans-serif"></font></TD>
<TD><font size="2" face="Arial, Helvetica, sans-serif">#ResultField1#</font></TD>
<TD><font size="2" face="Arial, Helvetica, sans-serif">#DateFormat(ResultField2, "mm/dd/yy"# <input type="hidden" name="eventdate" value="#Dateformat(ResultField2,"mm/dd/yy"#"</font></TD>
<TD><font size="2" face="Arial, Helvetica, sans-serif">#DateFormat(ResultField3, "mm/dd/yy"#</font></TD>
<TD><font size="2" face="Arial, Helvetica, sans-serif">#DollarFormat(ResultField6)#</font></TD>
<TD width="225"><INPUT type="radio" name="RecordID" value="#ResultField1#"></TD>
</tr>
</cfoutput>
<br>
<cfoutput>
<cfif startrow GTE maxrows>
<cfset startrow1 = #startrow# - maxrows>
<input type="Button" value="<< Previous #maxrows# Records" onclick="window.location='pendingorders.cfm?startrow=#startrow1#&ID=#URL.ID#'">
</cfif>
<cfset startrow = #startrow# + maxrows>
<cfif #selectordersub.recordcount# GTE startrow>
<input type="Button" value="Next #maxrows# Records >>" onclick="window.location='pendingorders.cfm?startrow=#startrow#&ID=#URL.ID#'">
</cfif>
</cfoutput>
<br>
<cfif #selectordersub.recordcount# EQ "0">
<font face="Arial, Helvetica, sans-serif" size="3" color="red"><b>You do not have any current orders pending.</b></font>
</cfif>
<br>
<br>
</table>
<div align="center">
<p align="left"></p>
</div>
</form>
I have a radio button validation script that should display an error message if no button is selected. It displays the error correctly when the form is submitted without a button being checked, but it also displays when the button is checked. Can someone look this over and let me know what is wrong?
Thanks!
---------------------------------------------------------------------------------------------------
The Script:
<Script Language="Javascript">
<!-- Begin
function checkRadios() {
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if(el.type == "radio" {
var radiogroup = el[el.name]; // get the whole set of radio buttons.
var itemchecked = false;
for(var j = 0 ; j < radiogroup.length ; ++j) {
if(radiogroup[j].checked) {
itemchecked = true;
break;
}
}
if(!itemchecked) {
alert("Please choose a record to commit this action on."
if(el.focus)
el.focus();
return false;
}
}
}
return true;
}
// End -->
</SCRIPT>
---------------------------------------------------------------------------------------------------
The Form:
<form action="pendingorders_RecordAction.cfm" method="post" name="menu" onsubmit="return checkRadios(this);">
<p align="left">
<INPUT type="submit" name="btnView_Delete" value="Cancel Order">
<INPUT type="submit" name="btn_View_Bill" value="View Order">
<input type="submit" name="btn_Edit_Bill" value="Edit Order">
<input type="submit" name="btnView_MainMenu" value="Return to Main Menu">
<cfoutput><input type="hidden" name="ID" value="#URL.ID#"</cfoutput>
</p>
<table border=0 cellpadding=3 cellspacing=0 size="600">
<tr>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF"></font></b></TD>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Order ID No:</font></b></TD>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Event Date:</font></b></TD>
<TD bgcolor="#000000"><B><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Date of Order:</font></B></TD>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Total Order Cost:</font></b></TD>
<TD bgcolor="#000000"><b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="2">Select Record:</font></b></TD>
</tr>
<cfparam name="startrow" default="1">
<cfparam name="maxrows" default="10">
<cfoutput query="selectordersub" maxrows="#maxrows#" startrow="#startrow#">
<TR bgcolor="###Iif(((CurrentRow MOD 2) is 0),de('FFA8A8'),de('FFFFFF'))#">
<TD><font size="2" face="Arial, Helvetica, sans-serif"></font></TD>
<TD><font size="2" face="Arial, Helvetica, sans-serif">#ResultField1#</font></TD>
<TD><font size="2" face="Arial, Helvetica, sans-serif">#DateFormat(ResultField2, "mm/dd/yy"# <input type="hidden" name="eventdate" value="#Dateformat(ResultField2,"mm/dd/yy"#"</font></TD>
<TD><font size="2" face="Arial, Helvetica, sans-serif">#DateFormat(ResultField3, "mm/dd/yy"#</font></TD>
<TD><font size="2" face="Arial, Helvetica, sans-serif">#DollarFormat(ResultField6)#</font></TD>
<TD width="225"><INPUT type="radio" name="RecordID" value="#ResultField1#"></TD>
</tr>
</cfoutput>
<br>
<cfoutput>
<cfif startrow GTE maxrows>
<cfset startrow1 = #startrow# - maxrows>
<input type="Button" value="<< Previous #maxrows# Records" onclick="window.location='pendingorders.cfm?startrow=#startrow1#&ID=#URL.ID#'">
</cfif>
<cfset startrow = #startrow# + maxrows>
<cfif #selectordersub.recordcount# GTE startrow>
<input type="Button" value="Next #maxrows# Records >>" onclick="window.location='pendingorders.cfm?startrow=#startrow#&ID=#URL.ID#'">
</cfif>
</cfoutput>
<br>
<cfif #selectordersub.recordcount# EQ "0">
<font face="Arial, Helvetica, sans-serif" size="3" color="red"><b>You do not have any current orders pending.</b></font>
</cfif>
<br>
<br>
</table>
<div align="center">
<p align="left"></p>
</div>
</form>