Wrox Programmer Forums
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 6th, 2004, 04:49 PM
Registered User
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old May 7th, 2004, 02:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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?





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP SESSION CONTENTS VARIABLES CAN'T BE CHANGED Epevas Classic ASP Components 8 January 30th, 2006 09:38 AM
session variables in asp to asp.net marvz ASP.NET 2.0 Basics 0 August 1st, 2005 03:09 AM
session variables and form parameters tacky BOOK: Beginning ASP 3.0 0 January 16th, 2005 09:36 PM
Passing Session Variables(ASP.NEt) to Jscript ank2go JSP Basics 1 February 26th, 2004 09:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.