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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp: prob with validation code

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
0
0
US
I have a multi-page form using asp and on my second page, (get_main_categories.asp) on submit, I run this javascript validation code against a bunch of checkboxes and it isn't working. It worked fine on win98 with pws, but then I incorporated it with my page layout; all formatted and everything and now it won't work. The incorporated page runs on IIS 5.0 with Windows 2000. Any clues as to why this doesn't work properly? My problem must lie in my javascript function, since everything works fine as long as I select at least one checkbox on get_main_categories.asp, but if I don't select any checkboxes and click next the next page doesn't get the info it needs to build the rest of the form and I get a missing operator error.

Here is my code for the get_main_categories.asp page:

<b><font color=&quot;#990000&quot;>Please select from the Main listing of Goods
and/or Services below: </font></b>
<p>
<%
Dim oConn, _
oRs
Dim sFld, _
sSql

Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
oConn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;./Purchasing.mdb&quot;) & &quot;;&quot;

sSql = &quot;SELECT GroupID, GroupName FROM Categories ORDER BY GroupName&quot;

Set oRs = oConn.Execute(sSql)

%>
<form name=&quot;supplyreg&quot; action=&quot;get_subcategories.asp&quot; method=&quot;post&quot; onSubmit=&quot;return validateCheckboxes(this);&quot;>
<%
For Each sFld In Request.Form
%>
<input type=&quot;hidden&quot; name=&quot;<%=Server.HtmlEncode(sFld) %>&quot; value=&quot;<%=Server.HtmlEncode(Request.Form(sFld)) %>&quot;><%
Next

Do Until oRs.Eof
%>
<input type=&quot;checkbox&quot; name=&quot;GroupID&quot; value=&quot;<%=oRs(&quot;GroupID&quot;) %>&quot;> <%=oRs(&quot;GroupName&quot;) %><br /><%
oRs.MoveNext
Loop
%>
<table BORDER=0 CELLSPACING=3 CELLPADDING=3 COLS=1 WIDTH=&quot;20%&quot;>
<tr>
<td> </td>
</tr>
</table>
<input type=&quot;submit&quot; value=&quot;Next &gt;&gt;&quot;>
</form>
<script language=&quot;Javascript&quot;>
function validateCheckboxes(formObj)
{
if(IsCheckboxChecked(formObj.GroupID))
{
return true;
}
else
{
alert('Please select one or more categories.')
return false;
}
}
</script>
<%
Set oRs = Nothing

Set oConn = Nothing
%>

AND HERE IS MY CODE FOR THE NEXT PAGE (get_subcategories.asp)

<b><font color=&quot;#990000&quot;>Please select from the Sub-Categories below:
: </font></b>
<p>
<%
Dim iGroupId
Dim oConn, _
oRs
Dim sFld, _
sSql

Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
oConn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;./Purchasing.mdb&quot;) & &quot;;&quot;

sSql = &quot;SELECT subcat.SubCatId, subcat.SubCatName, cat.GroupID, cat.GroupName&quot; & vbCrLf & _
&quot;FROM Subcategories subcat, Categories cat&quot; & vbCrLf & _
&quot;WHERE subcat.GroupID = cat.GroupID&quot; & vbCrLf & _
&quot; AND subcat.GroupID IN (&quot; & Request.Form(&quot;GroupID&quot;) & &quot;)&quot; & vbCrLf & _
&quot;ORDER BY cat.GroupName, cat.GroupID, subcat.SubCatName&quot;

Set oRs = oConn.Execute(sSql)

%>

<form action=&quot;submit_registration.asp&quot; method=&quot;post&quot; onSubmit=&quot;return validateCheckboxes(this);&quot;>
<%
For Each sFld In Request.Form
%>
<input type=&quot;hidden&quot; name=&quot;<%=Server.HtmlEncode(sFld) %>&quot; value=&quot;<%=Server.HtmlEncode(Request.Form(sFld)) %>&quot;><%
Next

Do Until oRs.Eof

If iGroupId <> oRs(&quot;GroupID&quot;) Then
If Not IsEmpty(iGroupId) Then
Response.Write vbCrLf & &quot;</blockquote>&quot;
End If

iGroupId = oRs(&quot;GroupID&quot;)

Response.Write vbCrLf & vbCrLf & &quot;<h1>&quot; & oRs(&quot;GroupName&quot;) & &quot;</h1>&quot; & vbCrLf & &quot;<blockquote>&quot;
End If
%>
<input type=&quot;checkbox&quot; name=&quot;SubCatId_<%=iGroupId %>&quot; value=&quot;<%=oRs(&quot;SubCatId&quot;) %>&quot;> <%=oRs(&quot;SubCatName&quot;) %><br /><%
oRs.MoveNext
Loop

If Not IsEmpty(iGroupId) Then
Response.Write &quot;</blockquote>&quot;
End If
%>

<input type=&quot;submit&quot; value=&quot;Next &gt;&gt;&quot;>
</form>
<script language=&quot;Javascript&quot;>
function validateCheckboxes(formObj)
{
var aGroups = formObj.GroupID.value.split(', ');

for(var iCnt = 0; iCnt < aGroups.length; iCnt++)
{
if(!IsCheckboxChecked(formObj['SubCatId_' + aGroups[iCnt]]))
{
alert('Please select one or more subcategories for the group, ' + formObj['GroupName_' + aGroups[iCnt]].value + '.')
return false;
}
}
return true;

return false;

}
</script>
<%
Set oRs = Nothing

Set oConn = Nothing
%>

I know its the javascript function, anyone know whats wrong? Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top