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: 1st form dependant on form in 2nd page

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
0
0
US
I have a form that contains misc information at the top and multiple checkboxes at the bottom of the form. The user can select one or more checkboxes (all have unique names and values.

I've coded each of my checkboxes on the 2nd page (may need include to do it efficiently) the same as the example below.

If Request.Form("ck_SnowRemEquip") = "-1" Then
strSnowRemEquip = "5600"
Else
strSnowRemEquip = ""
End If

The purpose of the above coding is to assign a variable the key to a table in an Access db to allow me to dynamically create a subset of checkboxes on the 2nd page. For example:
Checkboxes on first page:

ck_OfficeEquip, ck_OfcSupplies, ck_Roofing, ck_OfcFurniture,
ck_Computing, ck_FloorCvrng, ck_SnowRemEquip, etc.,

If the user checks ck_OfficeEquip, ck_OfcSupplies, and ck_OfcFurniture I need the next page to show a list of checkboxes for ck_OfficeEquip (calculators, printers, etc.,) a list of checkboxes for ck_OfcSupplies (staples, tape dispensers, pens, pencils, etc.,) and a list of checkboxes for ck_OfcFurniture (chairs, desks, file cabinets, etc.,). These lists would be generated from a table in my db using the 4-digit number I've assigned to the variable in my if statement.

My problem is I need to hold on to all data from both pages so that at the end of the 2nd page, after the user has made selections from the 2nd set of checkboxes on page 2 and they click submit, all of the data is added to the database. I have no idea how to write my sql so that I'm only getting the subsets for the items checked from page one. I'm sure there are other issues I'm going to have for this project, but thats my main stumbling block. I'm relatively new to asp and am also new to vbscript - does anyone have any suggestions?? Hopefully, I've explained this correctly so I'm not confusing everyone else as much as I've confused myself. All help would be monumentally appreciated!!!!!!!!!!! [sadeyes] [shadessad]
 
why not pass the values checked into hidden fields in the second page. thus allowing you to submit the values all at once as one form.

1H 1K 10 3D 3F 3E 3K 38 3J 10 1T 10 3G 3L 3I 35 10 35 3O 33 35 3C 3C 35 3E 33 35

brickyard.jpeg
Most intense event I ever attended!
 
I would still need the 2nd page to show the 2nd set of checkboxes which is dependant on the selections the user made on the first page of the form. To only have a one page form (which would probably be more complicated), I would have the generate each subset of checkboxes as the made there selection from the main set. IE.,

The user select ck_OfcSupplies and as soon as they checked the box, the checkboxes designating the different office supplies would have to appear - the user would select from that list and then maybe select from another major category and have more checkboxes generated as they select other major categories. I think it would be more complex and the validation would be more intense that way. Since I'm just learning all of this, I would think it would be easier to have the main form - pass that data onto page 2 (maybe using an include to pull the data from the table and create the new checkboxes - then i'm stuck.........i've never worked with arrays and don't really understand them.....

So........in other words..........HELP! Thanks for the suggestion though!!!
 
Ok - I've made a minimal amount of progress on this idea.
I've given the checkboxes on the first page a value, which is equal to the key of the table that need to generate the checkboxes on the next page.

I think?? I'll need to have an include to dynamically create the subset or subsets of checkboxes on the 2nd page, but am not sure how to go about it.
This would be the include if I was simple building the table of all subsets, but how would i base it on the value of the checkboxes from the previous page not being equal to ""????

<!--#include file=&quot;checkboxes.inc&quot;-->
<% 'Request the name of Category and the primary key
from the tblSubCategory table.
SQLCK=&quot;SELECT SubCategory, CategoryID FROM tblSubCategory&quot;
set connck = server.createobject(&quot;ADODB.Connection&quot;)
connck.open &quot;Checkboxes&quot;
set tblSubCategory=connck.execute(SQLCK)
%>

<% 'Loop thru recordset to make each entry in the list. %>
<% do while not tblSubCategory.eof %>
<tr>
<td><font face=&quot;Arial,Helvetica&quot; size=-1><%= tblSubCategory.Fields(&quot;SubCategory&quot;).Value %></font></td>
<td><input type=&quot;checkbox&quot; name=&quot;<%=tblSubCategory.Fields(&quot;CategoryID&quot;).Value %> value=&quot;-1&quot;></td>
</tr>

<%tblSubCategory.movenext
loop%>
 
selaine,
Have you tried using a WHERE clause?
Where are you on this project now?
 
I've done some rearranging of my code and have that particular problem solved. However, I have two other issues related to this project. If you could look at them, that would be great (I'll refer to thm at the bottom of this posting) - In the meantime, here is my solution to this problem.....

<html>
<head>
<meta name=&quot;Author&quot; content=&quot;Webmaster&quot;>
<title> - Supplier Registration - Select SubCategories Page</title>
</head>
<body>

<center><b><font face=&quot;Arial,Helvetica&quot;>Purchasing</font></b>
<br>
<form action=&quot;add_supplier.asp&quot; method=&quot;post&quot; name=&quot;subcategory&quot; onsubmit=&quot;return CheckIt();&quot;>
<input type=&quot;hidden&quot; Name=txtCompany value=&quot;<%=Request.Form(&quot;D_Company&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtAddress value=&quot;<%=Request.Form(&quot;D_Address&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtCity value=&quot;<%=Request.Form(&quot;D_City&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtState value=&quot;<%=Request.Form(&quot;D_State&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtZip value=&quot;<%=Request.Form(&quot;D_Zip&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtPhone value=&quot;<%=Request.Form(&quot;D_Phone&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtFax value=&quot;<%=Request.Form(&quot;D_Fax&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtWebsite value=&quot;<%=Request.Form(&quot;D_Website&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtContact value=&quot;<%=Request.Form(&quot;D_Contact&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtCPhone value=&quot;<%=Request.Form(&quot;D_CPhone&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtEmail value=&quot;<%=Request.Form(&quot;D_Email&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtDate value=&quot;<%=Request.Form(&quot;hidDate&quot;)%>&quot;>
<input type=&quot;hidden&quot; Name=txtNotify value=&quot;<%=Request.Form(&quot;notify&quot;)%>&quot;>

<%
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( &quot;ADODB.Connection&quot; )
dbConn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath( &quot;Purchasing.mdb&quot; ) & &quot;;&quot;

Response.Write( &quot;<h3><font color=&quot;&quot;#990000&quot;&quot;>Please select from the Sub-Categories below:&nbsp;</font></h3>&quot;)

'Get the main categories from the database. All we need at the moment is the identities
strSQL = &quot;SELECT GroupID FROM [Main_Categories]&quot;
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect &quot;MAJORERROR.ASP&quot;
End If

'Scan the form looking for checked boxes
While NOT rsMain.EOF
fld = Request.Form( &quot;ck&quot; & rsMain(&quot;GroupID&quot;)) 'Get the field from the form
If NOT (fld = False) Then 'Was the box checked
ArrayCheck( ArraySize ) = rsMain(&quot;GroupID&quot;) '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 &quot;NOTHINGSELECTED.ASP&quot;
End If

'Make the SQL string for the group selection
strSQL = &quot;SELECT GroupID, Description FROM [Main_Categories] WHERE &quot;

'Make our way through the array making the selections we want
For counter = 0 To ArraySize - 1
If counter > 0 Then strSQL = strSQL & &quot; OR &quot; 'Put the OR in if required
strSQL = strSQL & &quot;(GroupID=&quot; & ArrayCheck(counter) & &quot;)&quot;
Next

'Now sort the output
strSQL = strSQL & &quot; ORDER BY Description&quot;

'Get the sorted records we want from the database
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect &quot;MAJORERROR.ASP&quot;
End If

'Start the main category display loop
While NOT rsMain.EOF
'Write the table header
Response.Write( &quot;<table BORDER=1 CELLSPACING=5 CELLPADDING=5 WIDTH=&quot;&quot;65%&quot;&quot; >&quot; & vbCrLf )

'Write the title of the current selection block (or main category description)
Response.Write( &quot;<tr><td colspan=&quot;&quot;2&quot;&quot;><center><b><font face=&quot;&quot;Arial,Helvetica&quot;&quot; size=+1>&quot; & rsMain(&quot;Description&quot;) & &quot;</font></b></center></td></tr>&quot; & vbCrLf )

Response.Write( &quot;<td><input type=&quot;&quot;hidden&quot;&quot; Name=MainCat&quot; & rsMain(&quot;GroupID&quot;) & &quot; Value=&quot; & rsMain(&quot;GroupID&quot;) & &quot;></td>&quot; )



'--------------------------- 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 = &quot;SELECT CategoryID, Description FROM [Sub_Categories] &quot; & _
&quot;WHERE GroupID=&quot; & rsMain(&quot;GroupID&quot; ) & _
&quot; ORDER BY Description&quot;

'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(&quot;Description&quot;)%></td>
<td><input type=&quot;checkbox&quot; name=&quot;cksub<%=rsMain(&quot;GroupID&quot;)%>&quot; value=&quot;<%=rsSub(&quot;CategoryID&quot;)%>&quot;></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( &quot;</table><br><br>&quot; & vbCrLf )

rsMain.MoveNext
Wend

'--------- Display the submit and reset buttons ------------------------
%>
<table BORDER=0 CELLSPACING=5 CELLPADDING=5 COLS=2 WIDTH=&quot;65%&quot; >
<tr>
<td><center><input type=&quot;submit&quot; value=&quot;Finalize and Submit Registration&quot;></center></td>
<td><center><input type=&quot;Reset&quot; value=&quot;Reset Registration Form&quot;></center></td>
</tr>
</table>


</form>
<%
'Clean up database
dbConn.Close
Set dbConn = Nothing
%>

</body>
</html>


NEED HELP ON THESE ISSUES:

Issue 1: I have to make sure that the user selects at least one checkbox from each set created above (they will be dynamic so could be one or more sets) I've created this code which would run onsubmit,
<script LANGUAGE=&quot;JavaScript&quot;>
function CheckIt() {
f1=document.forms[0];
GroupOld='';
Count=1;
for (ix1=0; ix1<f1.length; ix1++) {
Name=f1[ix1].name;
if (Name.substring(0,5) == 'cksub') {
Group=Name.substring(5,7);
if (Group != GroupOld) {
if (Count == 0) {
alert('Group '+GroupOld+' has no checks.');
return false;
}
GroupOld=Group;
Count=0;
}
if (f1[ix1].checked) {
Count=Count*1+1;
}
}
}
if (Count == 0) {
alert('Group '+GroupOld+' has no checks.');
return false;
}
}
</script>

This code was suggested to me in another forum and it works, but I would much rather give the user a message that would mean something to them (like using the description) - anyway.....I'm working on this one, but my main concern is the next issue......

Issue 2:
I've created a separate posting in this forum -
Link: thread333-658687

 
Ok this would be much simple if i tell you what i understand and for that it';s a simple solution.

So you have lets say 2 tables and i presume they are related

1 it's with main categories
cat_id
cat_name

2nd it's with the subcategories
sub_id - it's own id
parent_id - the link with categories(cat_id)
sub_name

so on the first form just place the first table check boxes
I'll use kind of pseudocode for easyer writing
<%
while not rsCategories.eof
%>
<input type=checkbox name=category value=<%=rsCategories(&quot;cat_id&quot;)%>><%=rsCategories(&quot;cat_name&quot;)%>
<%
wend
%>
This should be ok.
now user check what he neds and goes to the second page.
Now if we used same name for the check boxex they will be in an Request.Form(&quot;category&quot;) array but we dont need to break it up( they are normaly a comma separated values) and we use them to get values from the second table
<%
'store this selection for later use
Session(&quot;categories_array&quot;)=Request.Form(&quot;category&quot;)

sql=&quot;select * from subcategories where parent_id in (&quot;&Request.Form(&quot;category&quot;)&&quot;)&quot;
%>

and now you should have all the subcategories related on what user selected.

This can be applied to eve more then 1 kind of categories or subcategories.

Not shure but maybe this would simplify thing up.
I'm shure it will cuz i've done it this way, much much simple.


________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top