PDA

View Full Version : Setting and Reading Cookies


hughesmi
02-11-2005, 10:24 PM
Can anyone help me out with a cookie example.

I have a dropdown list that reads from a database and the user needs to select there name before submitting the form.

I'm looking for way for the user to set there name once ( i.e the cookie) and then they don't need to keep choosing there name.

Thanks.

Basscyst
02-12-2005, 01:07 AM
This breaks it down good:

http://www.w3schools.com/asp/asp_cookies.asp

Basscyst

hughesmi
02-12-2005, 08:30 AM
Thanks for this. However, I was aware of this site already but I couldn't figure out how to put my idea into a working script. The instructions on w3schools are clear and I did try but to no success in fact I feel I was way off with at what I did try.

Brandoe85
02-12-2005, 08:43 AM
Can we see your code then?

hughesmi
02-12-2005, 09:16 AM
Here you go - dont laught to much!!! :)


<html>

<head>

<title></title>
</head>

<body>
<%
Response.Cookies("Name").Expires=#Feb 28,2005#
%>


<select onchange=""location.href='cookie_test.asp=' + this.value "">

<option>- Select</option>
<option value="<% Response.Cookies("Name")="Mike"%>">Mike</option>
<option value="<% Response.Cookies("Name")="Lucy"%>">Lucy</option>
</option>

<%
Name=Request.Cookies("Name")
response.write("<input type=""text"" name=""Agent_Name"" size=""20"" value="<% & Name %> ">
%>

</body></html>

Eskimo
02-12-2005, 05:55 PM
This wold be my first suggestion.
<select onchange="location.href='cookie_test.asp?name=' + this.value ">

Why do you have everything double quoted twice and agin?

miranda
02-14-2005, 06:56 AM
In answer to Eskimo

Anytime inside the delimiters <% and %> you have a string and want to display a double quote " you have to use 2 of them "".


Now my questions to hughesmi.
in regards to this line
<select onchange=""location.href='cookie_test.asp=' + this.value "">

First as eskimo probably meant to say, you do not have this inside of a script block therefore the onchange event is an empty string "" and cookie_test.asp is never passed to the the location.

Next, what are you trying to pass with this statement this.value ?

and Lastly move the last single quote , the placement of it needs to be after the arguments passed int he querystring.




Next you have a single

hughesmi
02-14-2005, 06:19 PM
I'm note sure what I am doing with the this.value. This why I need help?

I am I way off with what I need it to do?

Eskimo
02-14-2005, 06:42 PM
I'm guessing the double quotes is a VB thing, a language that I have had very little exposure to. Thank you for pointing that out to me.

Will the users name already be entered into the database at this point, or will new users see this same form?

miranda
02-15-2005, 06:56 AM
Try this

<select onchange="location.href='cookie_test.asp?name=<%=Request.Cookies("Name")%>'">


Cookies are Set with Response.Cookies("oreo")
and read with Request.Cookies("oreo")