IIS ASP - Javascript cookie "Type Mismatch" solution

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > May 2005 > Javascript cookie "Type Mismatch" solution





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Javascript cookie "Type Mismatch" solution
dmgauntt2002@yahoo.com

2005-05-31, 6:03 pm

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

Dave Anderson

2005-05-31, 8:50 pm

dmgauntt2002@yahoo.com wrote:
> function DateToExpires(myDate)
> {
> return
> String(theDate.getMonth())+"/"+theDate.getDate()+"/"+theDate.getFullYear();
> }


myDate and theDate ? Re-check your object names.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com