...

View Full Version : response.cookies("Contact")("ContactID") = ContactID



LeahSmart
06-23-2004, 01:56 PM
Hi Reader!

I need to set a cookie in JavaScript that will later be retrieved in ASP.

In ASP I would set the cookie as response.cookies("Contact")("ContactID") = ContactID. But I am not sure how to set it in JavaScript so ASP will pick it up.

All I can find is massive functions or millions of lines of code, and to be honest I haven?t a clue what they accomplish. Surely there is one line of code that can achieve the same as a line of ASP code would.

Any help would be great as I am really stuck on this one. :confused:

Thanks

Leah

Willy Duitt
06-23-2004, 02:02 PM
Did you try: document.cookie = ContactID; ?

Note: without and expiry date the cookie will be session only and will expire when the browser is closed. If you will need to set an expiration date you will need a few more lines of code however, not quite a million. ;)

If you need more help, you can try searching this forum. Cookie question have been asked and answered many times and there should also be several articles in the sticky FAQ at the top of this forum.

.....Willy

LeahSmart
06-23-2004, 02:07 PM
But I need to set the ContactID within a cookie called Contact, I have searched the forums and that has not helped. The cookie needs to expire when the browser closes.

Willy Duitt
06-23-2004, 02:24 PM
document.cookie='Contact='+ContactID;

LeahSmart
06-23-2004, 02:26 PM
But surely that will set Contact to the value if contact ID?

Willy Duitt
06-23-2004, 02:37 PM
That's what I thought you wanted.
I guess you'll have to wait until someone else comes along because quite frankly from what you have provided, I don't even know if ContactID is a variable, string or an input value....

Good Luck;

LeahSmart
06-23-2004, 04:10 PM
I want a cookie called contact to have multiple values, one of these values is contactID so COntact.ContactID = 12 for example and Contact.ContactName = 'Willy'

Willy Duitt
06-23-2004, 04:25 PM
Then either use an array or use a seperator within the string such as a semi-colon or pipe so that you can easily split it out to use later.

A quick search of this forums search feature using the keywords using cookies provided 407 threads and the second being cookie with multible values (http://www.codingforums.com/showthread.php?t=40530&highlight=cookies) which would seem to answer your question.

Read and follow the links......

LeahSmart
06-23-2004, 04:29 PM
I have looked at that already as I searched for cookies on the forum. I have followed the link to find the millions of lines of code I was talking about.

Willy Duitt
06-23-2004, 05:09 PM
<script type="text/javascript">
var id = 12;
var name = 'Willy';
var Contact = 'Contact.ContactID='+id+
'|Contact.ContactName='+name;
document.cookie = Contact;
alert(document.cookie.split('|')[0]+'\n'+document.cookie.split('|')[1])
</script>

LeahSmart
06-23-2004, 05:24 PM
Spliting it up is a good idea, but I need to be able to read it as a normal cookir through asp. I cannot change the other pages.

glenngv
06-24-2004, 05:58 AM
Try putting the key/value pairs (separated by &) in one cookie.

var ContactID = "123";
var ContactName = "blah";
var cookieValue = "ContactID=" + ContactID + "&ContactName=" + ContactName;
document.cookie="Contact=" + escape(cookieValue);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum