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 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    uk
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer want a field saved into a cookie and not a whole form

    i have attached a .txt file which includes a cookie script i found and would really like to use. the only problem is it saves all of the fields in the <form></form> and i only want it to save one (called first). i cant put this in a seperate <form></form> it has to be in the same one as the rest of the fields.

    can anyone tell me what code i should use instead of the one ive attached? i will be eternally grateful!!

    ps i think the new forums are great!!

    paul
    Attached Files Attached Files

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have been playing with cookies a little lately also. This code isn't really code that you can cope paste anywhere so it probably will not work exactly for you but if you modify the getNotes and saveNotes function then it might work. It is attached and I have tried to document it the best I could. If you have any questions I will try to answer them. Good luck.
    Attached Files Attached Files

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    uk
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im not any good with cookies yet - its still something ive not learnt how to do! i will play around with your code (thanks for that) but if anyone knows the exact code for me to use that i can just cut + paste into my site, please post it here!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    <script type="text/javascript">
    <!--// The Cookie Jar
    ////// Standard functions for Setting, Getting, and Deleting Cookies
    ////// John Krutsch, krutscjo@uvsc.edu

    function GetCookie (cookieName) {
    var regX = new RegExp("\\b" + cookieName + "=([^;]*)");
    var found = regX.exec(document.cookie);
    return (found) ? found[1] : "";
    }

    function SetCookie (name, value, expires, domain, path, secure) {
    var cstr = escape(name) + "=" + escape(value);

    if (expires>0){
    var expdate = new Date();
    expdate.setTime(expdate.getTime() + expires);
    expdate = expdate.toGMTString();
    cstr+="; expires=" + expdate;
    }

    if(domain) cstr+="; domain=" + domain;
    if(path || path=="") cstr+="; path=" + path;
    if(secure) cstr+="; secure";

    document.cookie = cstr;
    }

    function DeleteCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1000 * 60 * 60 * 24);
    document.cookie = name + "=" + escape(name) + "; expires=" + exp.toGMTString();
    }

    //-->
    </script>

    <body onload="document.f.eml.value=GetCookie('eml')">
    <form name="f">
    Name : <input type="text" value="" name="nme" />
    <br />
    Email: <input type="text" value="" name="eml" onchange="SetCookie(this.name,this.value,31536000)" />
    </form>

    For a complete breakdown of this particular cookie script you can See Chapter 35 0f Alex Vincent's JavaScript Developer's Dictionary

  • #5
    New Coder
    Join Date
    Jun 2002
    Location
    uk
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for that john, thats great! but there are 2 problems with it!

    1. it doesnt work with the default IE6 settings for restricting cookies! i had to manually change them to get it work (which most people wont know how to do). is there any way i can get this to work when IE is set as medium in the privacy settings?

    2. when adding "paul miller", it saves it as "paul%20miller" - is there a way to have it so it puts a space instead?

    thanks a lot, paul.


  •  

    Posting Permissions

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