Web Analytics Made Easy -
StatCounter want a field saved into a cookie and not a whole form - CodingForum


No announcement yet.

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

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!!

    Attached Files

  • #2
    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
    I try to convince 'em that I am computer geek, but I just can't do it. Why? Oh why?


    • #3
      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
        <script type="text/javascript">
        <!--// The Cookie Jar
        ////// Standard functions for Setting, Getting, and Deleting Cookies
        ////// John Krutsch, [email protected]

        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();


        <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)" />

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


        • #5
          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.