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 1 of 1

Thread: Cookie problems

  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookie problems

    Hello,

    I've been set this exercise that requires a web page to save text fields for login, password and save a checked tickbox. I've been fiddling around with it for hours on end, but no luck so far with any of it. I've looked on the internet, but the coding is a but different to what I've been using and I'm not quite sure what's going on. Here is what I've tried to do so far:

    function addCookie(tag, value) {
    var expireDate = new Date();
    var expireString = "";
    expireDate.setTime(expireDate.getTime() + (1000 * 60 * 60 * 24 * 365));
    expireString = "expires=" + expireDate.toGMTString();
    document.cookie = tag + "=" + escape(value) + ";" + expireString + ";";
    }

    function getCookie(tag) {
    var value = null;
    var myCookie = document.cookie + ";";
    var findTag = tag + "=";
    var endPos;

    if (myCookie.length > 0) {
    var beginPos = myCookie.indexOf(findTag);
    if (beginPos != -1) {
    beginPos += findTag.length;
    endPos = myCookie.indexOf(";", beginPos);
    if (endPos == -1)
    endPos = myCookie.length;
    value = unescape(myCookie.substring(beginPos, endPos));
    }
    }
    return value;
    }

    function saveLoginInfo() {
    if (document.CustomerLogin.ID.value != null) {
    addCookie("ID", document.CustomerLogin.ID.value)
    }

    if (document.CustomerLogin.ID.value != null) {
    addCookie("Password", document.CustomerLogin.Password.value)
    }

    addCookie("SavePassword", document.CustomerLogin.SavePassword.value)

    }


    function getLoginInfo() {
    var ID = getCookie("ID");

    var Password = getCookie("Password");

    var SavePassword = getCookie("SavePassword");
    if
    (document.CustomerLogin.SavePassword.checked == true)
    else (document.CustomerLogin.SavePassword.checked == false)

    }

    }

    We were given the 2 'generic functions' (addCookie() and getCookie()) that I tried to call on in the saveLoginInfo() and getLoginInfo() functions. I've placed saveLoginInfo() into the FORM tag using onSubmit, whilst I put getLoginInfo() into the BODY tag with the onLoad event handler.

    We were told that the saveLoginInfo() function is supposed to:
    - Save the login (named "ID") and password ("Password") fields if the save password checkbox is checked ("SavePassword").
    - Save the value of the checkbox

    getLoginInfo() is supposed to look for cookies saved, and then automatically repopulate the values on the form.

    For the saveLoginInfo function, I've tried to write the code that validates the information entered by the user in the login and password field, and the added the cookie. With getLoginInfo() I'm even more lost. I'm trying to tick the checkbox if getCookie recalls a value, but I'm pretty sure I'm way off track in what I've done.

    Any help would be much appreciated! Thanks!

    Christine
    Last edited by chiche; 05-24-2006 at 07:41 AM.


 

Posting Permissions

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