Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Devon, UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy response.cookies("Contact")("ContactID") = ContactID

    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.

    Thanks

    Leah

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Devon, UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    document.cookie='Contact='+ContactID;

  • #5
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Devon, UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But surely that will set Contact to the value if contact ID?

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;

  • #7
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Devon, UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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'

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 which would seem to answer your question.

    Read and follow the links......

  • #9
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Devon, UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #10
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <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>

  • #11
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Devon, UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •