I have a page that generates one or more lists of checkboxes via an access db. The code for page 1 (category.asp) is:
******************************
<% @LANGUAGE=VBscript %>
<% Option Explicit %>
<%
Response.Buffer = True
Dim dbConn 'Common Database connection
Dim rsConn 'Common recordset object
Dim strSQL 'SQL string constructor
'Get the database connection
Set dbConn = Server.CreateObject( "ADODB.Connection" )
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "seala.mdb" ) & ";"
'Get the main categories from the (seala.mdb) database; (Main Categories Table)
strSQL = "SELECT GroupID, Description FROM [Main Categories] ORDER BY Description"
Set rsConn = dbConn.Execute( strSQL )
If rsConn.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
%>
<html>
<head>
<title>Select Main Category</title>
</head>
<body>
<table align="center"><tbody>
<td colspan="2" class="thead">Select Main Categories</td>
<form name="maincat" action="subsection.asp" method="post">
<%
'Make our way through the main categories and write the data as we go
While NOT rsConn.EOF
%>
<tr><td><%=rsConn("Description"
%></td>
<td><input type="checkbox" name="chkbox<%=rsConn("GroupID"
%>"></td>
</tr>
<%
'Next record
rsConn.MoveNext
Wend
%>
<tr><td align="center" colspan="2">
<input type="submit" value="Submit Form"> <input type="reset" value="Reset Data">
</td></tr>
</form>
</tbody></table>
</body>
</html>
<%
'Clean up database objects
Set rsConn = Nothing
dbConn.Close
Set dbConn = Nothing
%>
***************************************
The second page called subsection.asp (this is where I'd prefer to generate a form per groupid) is:
***************************************
<% @LANGUAGE=VBscript %>
<% Option Explicit %>
<html>
<head>
<title>Select sub categories</title>
</head>
<body>
<form action="catgorysel.asp" method="post" name="subcategory">
<%
Response.Buffer = True
Dim dbConn 'Common Database connection
Dim rsMain 'Common recordset object
Dim rsSub
Dim strSQL 'SQL string constructor
Dim fld
Dim counter
Dim ArrayCheck(100)
Dim ArraySize
ArraySize = 0
'Get the database connection
Set dbConn = Server.CreateObject( "ADODB.Connection" )
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "seala.mdb" ) & ";"
'Get the main categories from the database. All we need at the moment is the identities
strSQL = "SELECT GroupID FROM [Main Categories]"
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
'Scan the form looking for checked boxes
While NOT rsMain.EOF
fld = Request.Form( "chkbox" & rsMain("GroupID"
) 'Get the field from the form
If NOT (fld = False) Then 'Was the box checked
ArrayCheck( ArraySize ) = rsMain("GroupID"
'Add the GroupID to the array
ArraySize = ArraySize + 1 'Increment the array size
End If
rsMain.MoveNext 'Next database record
Wend
Set rsMain = Nothing
'Check that something was selected
If ArraySize = 0 Then
Response.Redirect "NOTHINGSELECTED.ASP"
End If
'Make the SQL string for the group selection
strSQL = "SELECT GroupID, Description FROM [Main Categories] WHERE "
'Make our way through the array making the selections we want
For counter = 0 To ArraySize - 1
If counter > 0 Then strSQL = strSQL & " OR " 'Put the OR in if required
strSQL = strSQL & "(GroupID=" & ArrayCheck(counter) & "
"
Next
'Now sort the output
strSQL = strSQL & " ORDER BY Description"
'Get the sorted records we want from the database
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
'Start the main category display loop
While NOT rsMain.EOF
'Write the table header
Response.Write( "<table align=""center"">" & vbCrLf )
'Write the title of the current selection block (or main category description)
Response.Write( "<tr><td colspan=""2""><center><b><font face=""Arial,Helvetica"" size=+1>" & rsMain("Description"
& "</font></b></center></td></tr>" & vbCrLf )
Response.Write(strSQL)
Response.Write("Value in variable: ArraySize = "
Response.Write(ArraySize)
Response.Write( "<td><input type=""hidden"" Name=MainCount value=" & ArraySize & "></td>" )
Response.Write( "<td><input type=""hidden"" Name=MainCat" & rsMain("GroupID"
& "></td>" )
Response.Write( "<td><input type=""hidden"" Name=MainID value=" & rsMain("GroupID"
& "></td>" )
'--------------------------- BEGIN OF SUB-CATEGORY SECTION -------------------------
'Make the SQL string. We need all the categories that belong to the current main group
'and sort them into alphabetical order
strSQL = "SELECT CategoryID, Description FROM [Sub Categories] " & _
"WHERE GroupID=" & rsMain("GroupID" ) & _
" ORDER BY Description"
'Open the recordset
Set rsSub = dbConn.Execute( strSQL )
'Is there actually anything here
If NOT rsSub.EOF Then
'Start the scan loop
While NOT rsSub.EOF
'This is pretty much the same thing as in category.asp
%>
<tr><td><%=rsSub("Description"
%></td>
<td><input type="checkbox" name="catbox<%=rsSub("CategoryID"
%>"></td>
</tr>
<%
rsSub.MoveNext %>
<% Wend
End If
'Clean up recordset object
Set rsSub = Nothing
'---------------------------- END OF SUB-CATEGORY SECTION --------------------------
'End of the category table
Response.Write( "</table><br><br>" & vbCrLf )
rsMain.MoveNext
Wend
'--------- Display the submit and reset buttons ------------------------
%>
<div align="center">
<input type="submit" value="Submit Form"> <input type="Reset" value="Reset Form">
</div>
</form>
</body>
</html>
<%
'Clean up database
dbConn.Close
Set dbConn = Nothing
%>
My question is this: To make it easier for me, as a beginner to validate that the user selected at least on checkbox from each group that's generated, how would I generate the checkboxes so that for each groupid and subsequent checkboxes, a dynamically named form is created? That way, I could run validation per form on the page, rather than storing the groupid, and then determining which checkboxes were tied to which groupid....I think that would be more complicated.
Anyway, I would really appreciate any guidance on this if you have time. The entire project is so huge overall that I've been working on it for months and the validation for subsection.asp checkboxes is all I have left to do. The powers that be really want me to have this project completed by Thursday! If you don't have time, I'll understand....afterall you can't help everyone.... Any help or pointers in the right direction would be hugely appreciated!!!!! Thanks!
******************************
<% @LANGUAGE=VBscript %>
<% Option Explicit %>
<%
Response.Buffer = True
Dim dbConn 'Common Database connection
Dim rsConn 'Common recordset object
Dim strSQL 'SQL string constructor
'Get the database connection
Set dbConn = Server.CreateObject( "ADODB.Connection" )
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "seala.mdb" ) & ";"
'Get the main categories from the (seala.mdb) database; (Main Categories Table)
strSQL = "SELECT GroupID, Description FROM [Main Categories] ORDER BY Description"
Set rsConn = dbConn.Execute( strSQL )
If rsConn.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
%>
<html>
<head>
<title>Select Main Category</title>
</head>
<body>
<table align="center"><tbody>
<td colspan="2" class="thead">Select Main Categories</td>
<form name="maincat" action="subsection.asp" method="post">
<%
'Make our way through the main categories and write the data as we go
While NOT rsConn.EOF
%>
<tr><td><%=rsConn("Description"
<td><input type="checkbox" name="chkbox<%=rsConn("GroupID"
</tr>
<%
'Next record
rsConn.MoveNext
Wend
%>
<tr><td align="center" colspan="2">
<input type="submit" value="Submit Form"> <input type="reset" value="Reset Data">
</td></tr>
</form>
</tbody></table>
</body>
</html>
<%
'Clean up database objects
Set rsConn = Nothing
dbConn.Close
Set dbConn = Nothing
%>
***************************************
The second page called subsection.asp (this is where I'd prefer to generate a form per groupid) is:
***************************************
<% @LANGUAGE=VBscript %>
<% Option Explicit %>
<html>
<head>
<title>Select sub categories</title>
</head>
<body>
<form action="catgorysel.asp" method="post" name="subcategory">
<%
Response.Buffer = True
Dim dbConn 'Common Database connection
Dim rsMain 'Common recordset object
Dim rsSub
Dim strSQL 'SQL string constructor
Dim fld
Dim counter
Dim ArrayCheck(100)
Dim ArraySize
ArraySize = 0
'Get the database connection
Set dbConn = Server.CreateObject( "ADODB.Connection" )
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "seala.mdb" ) & ";"
'Get the main categories from the database. All we need at the moment is the identities
strSQL = "SELECT GroupID FROM [Main Categories]"
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
'Scan the form looking for checked boxes
While NOT rsMain.EOF
fld = Request.Form( "chkbox" & rsMain("GroupID"
If NOT (fld = False) Then 'Was the box checked
ArrayCheck( ArraySize ) = rsMain("GroupID"
ArraySize = ArraySize + 1 'Increment the array size
End If
rsMain.MoveNext 'Next database record
Wend
Set rsMain = Nothing
'Check that something was selected
If ArraySize = 0 Then
Response.Redirect "NOTHINGSELECTED.ASP"
End If
'Make the SQL string for the group selection
strSQL = "SELECT GroupID, Description FROM [Main Categories] WHERE "
'Make our way through the array making the selections we want
For counter = 0 To ArraySize - 1
If counter > 0 Then strSQL = strSQL & " OR " 'Put the OR in if required
strSQL = strSQL & "(GroupID=" & ArrayCheck(counter) & "
Next
'Now sort the output
strSQL = strSQL & " ORDER BY Description"
'Get the sorted records we want from the database
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
'Start the main category display loop
While NOT rsMain.EOF
'Write the table header
Response.Write( "<table align=""center"">" & vbCrLf )
'Write the title of the current selection block (or main category description)
Response.Write( "<tr><td colspan=""2""><center><b><font face=""Arial,Helvetica"" size=+1>" & rsMain("Description"
Response.Write(strSQL)
Response.Write("Value in variable: ArraySize = "
Response.Write(ArraySize)
Response.Write( "<td><input type=""hidden"" Name=MainCount value=" & ArraySize & "></td>" )
Response.Write( "<td><input type=""hidden"" Name=MainCat" & rsMain("GroupID"
Response.Write( "<td><input type=""hidden"" Name=MainID value=" & rsMain("GroupID"
'--------------------------- BEGIN OF SUB-CATEGORY SECTION -------------------------
'Make the SQL string. We need all the categories that belong to the current main group
'and sort them into alphabetical order
strSQL = "SELECT CategoryID, Description FROM [Sub Categories] " & _
"WHERE GroupID=" & rsMain("GroupID" ) & _
" ORDER BY Description"
'Open the recordset
Set rsSub = dbConn.Execute( strSQL )
'Is there actually anything here
If NOT rsSub.EOF Then
'Start the scan loop
While NOT rsSub.EOF
'This is pretty much the same thing as in category.asp
%>
<tr><td><%=rsSub("Description"
<td><input type="checkbox" name="catbox<%=rsSub("CategoryID"
</tr>
<%
rsSub.MoveNext %>
<% Wend
End If
'Clean up recordset object
Set rsSub = Nothing
'---------------------------- END OF SUB-CATEGORY SECTION --------------------------
'End of the category table
Response.Write( "</table><br><br>" & vbCrLf )
rsMain.MoveNext
Wend
'--------- Display the submit and reset buttons ------------------------
%>
<div align="center">
<input type="submit" value="Submit Form"> <input type="Reset" value="Reset Form">
</div>
</form>
</body>
</html>
<%
'Clean up database
dbConn.Close
Set dbConn = Nothing
%>
My question is this: To make it easier for me, as a beginner to validate that the user selected at least on checkbox from each group that's generated, how would I generate the checkboxes so that for each groupid and subsequent checkboxes, a dynamically named form is created? That way, I could run validation per form on the page, rather than storing the groupid, and then determining which checkboxes were tied to which groupid....I think that would be more complicated.
Anyway, I would really appreciate any guidance on this if you have time. The entire project is so huge overall that I've been working on it for months and the validation for subsection.asp checkboxes is all I have left to do. The powers that be really want me to have this project completed by Thursday! If you don't have time, I'll understand....afterall you can't help everyone.... Any help or pointers in the right direction would be hugely appreciated!!!!! Thanks!