Print Page | Close Window

asp deleting cookies

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=14491
Printed Date: 30 March 2026 at 11:29am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: asp deleting cookies
Posted By: riya_singtel
Subject: asp deleting cookies
Date Posted: 30 March 2005 at 9:57pm
I am working on cookies in asp and I need an option to delete the cookie when a button is clicked. So i just write an empty string in it.
 
I set the cookies as:
Response.Cookies("name")="Henry"
 
The code for button is:
<INPUT type="button" value="Remove" OnClick="removeCookie">
 
The code for deleting the value is:
<SCRIPT language="VBSCRIPT">
Sub RemoveCookie
     document.cookie = "name="
End Sub
</SCRIPT>
 
However I realise that this creates a duplicate cookie named name without any value( Checked it by retrieving all cookies).I guess one copy is created at the client and other at the server which gives me erroneous results when i access the value of the cookie later.
 
I can reset the value of the cookie uisng Response.Cookies but i do not know how to implement it on  a button click.
 
Any proposed solns shall be appreciated.
thanks



Replies:
Posted By: Phat
Date Posted: 30 March 2005 at 11:09pm
Google is your friend

http://www.webreference.com/js/column8/functions.html - http://www.webreference.com/js/column8/functions.html

/*
name - name of the cookie
[path] - path of the cookie (must be same as path used to create cookie)
[domain] - domain of the cookie (must be same as domain used to
create cookie)
path and domain default if assigned null or omitted if no explicit
argument proceeds
*/

function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}



Posted By: riya_singtel
Date Posted: 31 March 2005 at 4:29am

thanks...i'll try it out and let u know..




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net