Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie Creation and Deletion

Status
Not open for further replies.

dinosf

Technical User
Dec 27, 2002
11
0
0
Hi guys - I have an issue (mainly that I know so little about javascript) in an asp.net page I am creating. On the page I have several drop down lists that I use the value of the selected value to create a cookie, then on page load I look for that cookie value and depending on what it is I know which drop down list was selected then I parse the string in the sub I call to complete the actions I need. The issue I'm having is getting rid of the cookie and/or setting it's value to nothing. I know I can set the timeout value to a negative value, and I've tried just using repsonse.cookies to change the value. So I'm thinking the problem is one with the path.

I don't know how to modify the cookie creation script to specify the path so when I use response.cookies it's not finding it. If javascript has a default path I might be able to access it with response cookies("../Path/"Values") = ""

or if someone has a better path to reccommend I'm all ears.

I don't need the cookie values after I retrieve them once, so removing it entirely works too. I do have a very specific reason for using cookies instead of regular asp.net session variables.

Here's how I add the value to the drop down list--------
Dim nli As New ListItem
nli.Value = arrR(q, 8)
nli.Text = intMos & " / " & intMiles
Dim strResult As String
strResult = "CreateCookie(this, 'TermCall');this 0].selected=true;"

ddlTerm.Attributes("onChange") = strResult
Me.ddlTerm.Items.Add(nli)

The script to create the cookie is in the html portion of the page -------
<SCRIPT language="JavaScript">

function CreateCookie(myListBox, varType)
{
var txtPlan;

txtPlan = myListBox[myListBox.selectedIndex].value;
document.cookie = "Values"+'='+varType+'|'+txtPlan;
}

</SCRIPT>

I need very specific help, as I seem to have a mental block on it today. Thanks.
 
That's the issue I'm having - I don't know how to modify the script in the html side to add in the path, and if I use that method I need to know where the path leads so I can specify it in the aspx side (e.g. if the page that creates the cookie is located at ./ is the cookie designation for the path "/" the same location? when i use response.Cookies("Values") = "" - it does not work it sets a different cookie as nothing, which makes me think the path is different

about the script - I know there is a date item to be added in too - and I'm not sure of the sytax to add in the patch correctly as I don't realy work much with javascript I'm just trying to solve a post back issue with this page.
txtPlan = myListBox[myListBox.selectedIndex].value;
document.cookie = "Values"+'='+varType+'|'+txtPlan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top