I'd rename your checkbox
<input type="checkbox" name="chk_<%=(rsRegionAssc
Then on the next page
for each x in request.form
if left(x.name,4)="chk_" then
session(mid(x.name,5)) = request(x)
end if
next
Main Topics
Browse All Topicshello folks, here goes......
I have a form on an asp page and within that form there is a repeat region that loops through a recordset. The code for this is below.
<%
While ((Repeat1__numRows <> 0) AND (NOT rsRegionAsscociation.EOF))
If Repeat1__numRows mod 2 Then
strBGColor = "#e8e8e8"
Else
strBGColor = "#FFFFFF"
End If
%>
<tr>
<td align="right" valign="top" class="td_darkblue">
<td> </td>
<td align="center" bgcolor="<%=strBGColor%>">
<td bgcolor="<%=strBGColor%>">
</tr>
<%
Repeat1__index=Repeat1__in
Repeat1__numRows=Repeat1__
rsRegionAsscociation.MoveN
Wend
%>
As you can see from the code above I set the name of the checkboxes dynamically using the name of a recordset value on each loop through the recordset.
The form targets another page where Session Variables are set for ALL form fields.
What I need is to dynamically create SINGLE Session Variables for each dyanmic checkbox. So for each dynamic checkbox that is checked I want to set a session variable for it with a value of 1, the session variable has to have the same name as checkbox.
I need it to work like this so that no matter how many dynamically created checkboxes there are in the form, there is always a corresponding session variable for it.
12 dyanmic checkboxes = 12 session variables
anyone have any ideas? :)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
What Gary said is a good idea. The X is just a temporary variable used to iterate through the form collection. In this case, X will eventually assume the identity of all of your checkboxes from the previous page. The code Gary has provided should be on your processing page, and is the most efficient way of discovering your dynamic checkboxes ( short of actually using a recordset again to get the field values). You should not prefix any other form elements with chk_.
This being said, do you have any other design options? Session variables are bad enough as is, but an unknown number could really cause you problems down the road. Besides, how will other programs in your web be aware of which Session variables exist if they are always dynamic? You may want to consider a more efficient design if possible. If you must do it this way, I cant think of a better way then what Gary said.
The x stands for nothing its a kinda shorthand way of referencing the previous form elements. (I made an error with using x.name)
Try this simple example
<form method=post action=ee44.asp>
Box 1 <input type=checkbox name=chk_box1 value=1>
Box 2 <input type=checkbox name=chk_box2 value=2>
Box 3 <input type=checkbox name=chk_box3 value=3>
<input type=submit>
</form>
ee44.asp
<%
for each x in request.form
if left(x,4)="chk_" then
session(mid(x,5)) = request(x)
end if
next
response.write "Box1 = " & session("box1") & "<BR>"
response.write "Box2 = " & session("box2") & "<BR>"
response.write "Box3 = " & session("box3") & "<BR>"
%>
Which ever checkboxes you select they will be placed into a session variable and printed on the next page.
SimonWGoldsmith ,
Try this approach...
Create a dynamic checkboxes with the same name but the value will the actual recordset
<input type="checkbox" name="chkbox" value="<%=(rsRegionAsscoci
try to check out the link of rmore info...
http://oldlook.experts-exc
Or if you just one session value then you can try this....
Now what you just need to do is to session this value...
like for example
session("chkbox") = request.form("chkbox")
If you want to retrieve the values of the session... since making the checkbox the same will make it a comma seperated string
Then you will just manipulate using split function... like this
arraysesssion = split(session("chkbox")
for i=Lbound(arraysession) to Ubound(arraysession)
response.write arraysession(i)
next
This way you will only deal and track one session variables...
HTH...
HAppy programming...
As for not using session variables for a three page form, take Gary's code:
for each x in request.form
if left(x,4)="chk_" then
Response.Write "<input name='" & X & "' value = '" & request(x) & "'>"
end if
next
These will make hidden form variables that will be passed to the third page, and can then be accessed again using Garys Loop
SimonWGoldsmith,
I think the approach that I had given to you will work...
If you will pass the checkbox data into another form... then you can put in a hidden field... Using split fucntion you can seperate the data...
Now when you process the data on the 3rd form you will again put it in a hidden field to again manipulate the data using split function just like I had mention...
I wish I could have more time to spare but I got to go... need to sleep...
Hope this help...
Happy programming...
Right I now have the following and session variables are getting set for each checkbox in the form.
'Region Association rules 1
session("RegionAssociation
arrayRegions = split(session("RegionAssoc
for i=Lbound(arrayRegions) to Ubound(arrayRegions)
session("Region"&i) = arrayRegions(i)
next
What will the session variables be called on another page???
How do I reference them, I'm abit confusedas to what the names fo the session variables will be. :(
Will the session variables be called Session("Region1") - Session("Region14") say?
Stick with my original solution and kblacks amendment
Place this on pages 2 and 3
for each x in request.form
if left(x,4)="chk_" then
Response.Write "<input name='" & X & "' value = '" & request(x) & "'>"
end if
next
Then on the final page where you do whatever with the variables you just use an amendment of the code
for each x in request.form
if left(x,4)="chk_" then
' What do you want to do now with all the variables.
end if
next
SimonWGoldsmith,
Below are three fiel to simulate my approach...
just cut ans paste
=======save this as SimonWGoldsmith-1.asp
<%
'Since the data is comming form the db
' I will just create an array for the data to be out in the check box
teststr = "checkbox1,checkbox2,check
%>
<form name="form1" method="post" action="SimonWGoldsmith-2.
<table width="75%" border="0">
<tr>
<td>Select</td>
<td> Description</td>
</tr>
<%
arrayteststr = split(teststr,",")
for i = Lbound(arrayteststr) to Ubound(arrayteststr)
%>
<tr>
<td><input name="chkbox" type="checkbox" value="<%=arrayteststr(i)%
<td><%=arrayteststr(i)%></
</tr>
<%next%>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
========save this as SimonWGoldsmith-2.asp
<%session("chkbox") = request.form("chkbox")%>
<form name="form1" method="post" action="SimonWGoldsmith-3.
<input name="chkbox" type="hidden" value="<%=request.form("ch
Below is the output using the request("chckbox")
1. using the .count property
<table width="75%" border="0">
<tr>
<td>Select checkbox</td>
</tr>
<%
for i = 1 to request.form("chkbox").cou
%>
<tr>
<td><%=request.form("chkbo
</tr>
<%next%>
</table>
<br>
<br>
2. using the request collection and gettin the elemname
<table width="75%" border="0">
<tr>
<td>Select checkbox</td>
</tr>
<%
for each elem in request.form("chkbox")
%>
<tr>
<td><%=elem%></td>
</tr>
<%next%>
</table>
<br>
<br>
3. using the session
<table width="75%" border="0">
<tr>
<td>Select checkbox</td>
</tr>
<%
arraysession = split(session("chkbox"),",
for i = Lbound(arraysession) to Ubound(arraysession)
%>
<tr>
<td><%=arraysession(i)%></
</tr>
<%next%>
</table>
<br>
<br>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</form>
=======SimonWGoldsmith-3.a
<%
if request.form("test") <> "" then
response.write "Below are the selected checkbox using session <br>"
arraysession = split(session("chkbox"),",
for i = Lbound(arraysession) to Ubound(arraysession)
response.write arraysession(i) & "<br>"
next
response.write "Below are the selected checkbox using hidden field <br>"
arrayhidden = split(request.form("chkbox
for i = Lbound(arrayhidden) to Ubound(arrayhidden)
response.write arrayhidden(i) & "<br>"
next
else
response.write "Please input a char on the textbox to see the output"
end if
%>
<br><br>
if you will use rin another form then you will just the name of the hidden field...
Since the hidden field is comma delimited as well as the session..<br>
You can use split which is used on the third solution...<br>
But if you still need to pass it on a form just put agin it in a hidden field...
<form name="form1" method="post" action="SimonWGoldsmith-3.
<input name="chkbox" type="hidden" value="<%=request.form("ch
<table width="75%" border="0">
<tr>
<td>Name</td>
<td><input name="test" type="text"></td>
</tr>
<td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
========
HTH...
HAppy programming...
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Split Points kblack / GaryC123
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
GaryC123
EE Cleanup Volunteer
Business Accounts
Answer for Membership
by: SimonWGoldsmithPosted on 2003-10-10 at 03:53:29ID: 9526695
I think the code I need for the target page is something like what I have already written below, but it contains syntax errors I guess cos of the punctuation.
onName")) >") = Request.Form("<%=strRegion Name%>") >") xt()
<%
While Not rsRegionAssociation.EOF
strRegionName = (rsRegionAssociation("Regi
Session("<%=strRegionName%
response.Write Session("<%=strRegionName%
rsRegionAssociation.MoveNe
Wend
%>