Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Javascript cookie "Type Mismatch" solution

Reply
Thread Tools

Javascript cookie "Type Mismatch" solution

 
 
dmgauntt2002@yahoo.com
Guest
Posts: n/a
 
      05-31-2005
I have some javascript ASP code that sets the expiry date on a cookie
to five years from now. The code worked until today, when I got the
following error message:

Microsoft JScript runtime (0x800A000D)
Type mismatch

The code was

var expiryDate=new Date();
expiryDate.setYear(expiryDate.getYear()+5);

Response.Cookies(cookieName).Expires=DateToExpires (expiryDate);

function DateToExpires(myDate)
{
return
String(theDate.getMonth())+"/"+theDate.getDate()+"/"+theDate.getFullYear();
}

DateToExpires returns "4/31/2010"; this is the correct format for
Expires.

See the problem? APRIL HAS ONLY 30 DAYS! I forgot that the value of
theDate.getMonth() runs from 0 to 11. The proper code is

function DateToExpires(myDate)
{
return
String(theDate.getMonth()+1)+"/"+theDate.getDate()+"/"+theDate.getFullYear();
}

which returns "5/31/2010" (which is actually 5 years from now!)

I hope that this helps someone.

- David Gauntt

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cookie Question (IP as domain and cookie file location) =?Utf-8?B?UGF1bA==?= ASP .Net 1 01-10-2006 08:37 PM
Any downsides to cookie assignment inside custom class using HttpContext.Current? ASP.NET 2.0 cookie fix? ASP .Net 2 08-17-2005 06:43 AM
Cookie and Session Cookie Questions. Shapper ASP .Net 1 04-27-2005 11:20 AM
Session cookie? Browser instance cookie? Ben ASP .Net 3 06-03-2004 03:41 AM
Retrieving cookie data through document.cookie (Javascript) Vikram Bhatia Javascript 1 10-11-2003 12:54 PM



Advertisments