|
|
 |
| ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP Forms section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|

May 6th, 2004, 05:49 PM
|
|
Registered User
|
|
Join Date: May 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ASP Form Data - Using Session Variables
How do I convert form variables to Session variables?
Say, for instance, that the user clicked on a checkbox and submitted the form, and the checkbox they submitted was called "item1" in the form handler. I know that when I do the following in the form handler, the following works to output the data:
<%
dim item1,item2
item1 = request.querystring("checkbox1")
item2 = request.querystring("checkbox2")
if item1="checkbox" then response.write("The item you selected is "&item1)
if item2="checkbox" then response.write("The item you selected is "&item2)
%>
This works perfectly, but if they close the page, everything goes away. I want what they selected to carry with them until they manually close the session by checking out.
How would I summarize all data from the form and attach/convert it to their session, so when they go somewhere else in my site, the results from the previous form sticks with them? Realistically, how could I take variable "item1" and have it apply to a final form?
|

May 7th, 2004, 03:48 AM
|
 |
Wrox Author
Points: 33,554, Level: 80 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
|
|
Hi there,
You can simply save the values you want to Session variables, and later use them again:
Code:
If item1 = "checkbox" Then
Session("CheckBox1") = True
End If
Later in your form, you can use this code to preselect the item again:
Code:
Dim CheckedString
If Session("CheckBox1") = True Then
CheckedString = " checked=""checked"""
End If
...
<form>
<input name="checkbox" type="checkbox" value="checkbox"<%=CheckedString%> />
</form>
When the page is loaded, CheckedString will get a value if the Session value equals True. The value of " checked=""checked"" for the CheckedString variable will end up in the checkbox like this:
<input name="checkbox" type="checkbox" value="checkbox" checked="checked" />
causing the checkbox to be selected.
The example I gave is quite verbose, to demonstrate the concept. In reality, you can compact the code a bit by saving the checked="checked" string as the Session variable's value or by using Response.Write to write out the checkbox inside the If statement.
All solutions would work equally well, so it's just a matter of personal preference.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: 3 Libras by A Perfect Circle (Track 18 from the album: Thirteenth Step) What's This?
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |