Jump to content

Session variables with forms


matthewordie

Recommended Posts

Hi, first off I have zero knowledge of asp coding so go easy on me please. :) I'm trying to carry the value of my forms over from page to page. I'm looking for a very simple way to do this. My code is all javascript and I thought about using cookies, but my teacher suggested asp session variables since I have a small asp file that sends my form data to my email already. Anyways here is my page so you can see what I'm talking about...http://matc.studentsites.net/restorff/vico...final/shop.htmlI'd like the add button just to send the number of that item to a session variable or cookie. Then when the user goes to the "shopping cart" page, I can list the items and amount the user selected. Also I'd like to have a dollar amount attached to the items to make a total. Then I'd like to send that over to the checkout page as well. It will then email all the information to myself. As you can see its a very poor excuse for a shopping cart but its just for show. Any ideas what I can do? I can post my asp code if need be as well.

Link to comment
Share on other sites

Here is the tutorial on how to use the session in ASP:http://www.w3schools.com/asp/asp_sessions.aspYou will use the Request object to get information from the form. The Request.Form collection holds information submitted in the form, and the Request.Querystring collection holds information submitted in the URL. You can add those items to the session object and get them on later pages.

Link to comment
Share on other sites

I'm still a little confused. So I submit my form data to an asp page with the "action="aspfile.asp". I then use the Request.Form to grab the data. How can I put the data back onto the page? So what would the code for the asp be?

<%Session.Request.Form = variable%>

I guess I'm really unclear about the whole thing still. ~_~

Link to comment
Share on other sites

If you have a text field, say the name is "field1", you would get the value on the processing page like this:

<%field_value = Request.Form("field1")%>

If you want to display it on the page, you can either use Response.Write or a shortcut. You can insert the ASP directly in the middle of your HTML where you want to display it. These two lines do the same thing:

The value of the field is <% Response.Write(field_value) %>The value of the field is <%=field_value%>

If you want to add it to the session, you do it like this:

<%Session("field1") = field_value%>

Check the references in the ASP section of the w3schools site for some more info.

Link to comment
Share on other sites

You would need to use AJAX to submit the form with Javascript. AJAX allows updates to the page without changing the page, and it uses Javascript objects to send the request and get the response from the server. If you want to learn about AJAX, the best way is to probably do a Google search for it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...