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 11 of 11
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript:Notes

    i've been looking all over the place and can't find it.


    OK i need a code that stores a cookie for your "notes"..

    Example:

    Enter your notes:

    Remember to pick up the "whatever"...

    *saved*

    Come back

    Remember to pick up the "whatever"...
    Remember to buy "laptop"......
    *saved*



    The real idea is i'm creating a webbrowser.... Like IE... And it's not that good yet so a code will be the Favorites......

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts
    You can use or modify this:

    globalCookie.js
    PHP Code:
    // globalCookie.js
    var expDate = new Date();

    function 
    setCookie(isName,isValue,daysExpire) {
      if (
    daysExpire) { expDate.setTime(expDate.getTime()+24*60*60*1000*daysExpire); }
      else {
    expDate.setTime(expDate.getTime()+24*60*60*1000*360); }
    //  document.cookie = isName+"="+isValue+";expires="+expDate.toGMTString();
      
    document.cookie isName+"="+escape(isValue)+";expires="+expDate.toGMTString();
    }

    function 
    getCookie(isName) {
      var 
    cookieStr document.cookie;
      var 
    startSlice cookieStr.indexOf(isName+"=");

      if (
    startSlice == -1) {return false}
      var 
    endSlice cookieStr.indexOf(";",startSlice+1);
      if (
    endSlice == -1) { endSlice cookieStr.length; }
      var 
    isData cookieStr.substring(startSlice,endSlice);
      var 
    isValue isData.substring(isData.indexOf("=")+1,isData.length);
      return 
    unescape(isValue);
    }

    function 
    dispCookie(isName) {
      var 
    nValue getCookie(isName);
      return (
    nValue);
    }

    function 
    deleteCookie(isName) {
      if (
    getCookie(isName)) { 
        
    document.cookie isName "="+"; expires=Thu, 01-Jan-70 00:00:01 GMT"; }

    PHP Code:
    <html>
    <
    head> <title>kookieDemo </title>
    <
    STYLE type="text/CSS"></STYLE>
    <
    SCRIPT src="globalCookie.js"></SCRIPT>

    <!-- Following is not used in this version
    <script type="text/javascript">
    function fetch(){
      k=dispCookie('testCook')
      document.getElementById('MyTest').value=k
    }
    </script>
    -->

    </head>
    <!-- body onload="fetch()" --><!-- Use to automatically fetch saved cookie -->

    <body>
    <button onclick="setCookie('testCook',document.getElementById('MyTest').value,5)">Save Note</button>
    <button onclick="getCookie('testCook',document.getElementById('MyTest').value,5)">Get Note</button>
    <button onclick="document.getElementById('MyTest').value=''">Clear Note</button>
    <button onclick="document.getElementById('MyTest').value=dispCookie('testCook')">Display Note</button>
    <button onclick="deleteCookie('testCook',document.getElementById('MyTest').value,5)">Delete Note</button>
    <br>
    <textarea ID="MyTest" ></textarea>

    <!--
    It works great. 
    The third argument of "setCookie()" can be left off, 
    it identifies how many days until expiration (default is 360 days.)
    -->
    </body>
    </html> 
    Keep in mind that 'cookies' cannot be shared at different computers.
    Only keeps the 'notes' on the calling computer.

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't get this code to work!


    I put in the code and.... i got the text box but it would keep the notes!

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts
    Two questions:
    1. Did you save BOTH files to the same directory?
    2. What browser are you using and is your javascript enabled?

  • #5
    Regular Coder
    Join Date
    Oct 2006
    Posts
    107
    Thanks
    3
    Thanked 5 Times in 5 Posts
    That was the code I was working on awhile ago. Dr_J helped me with that and I worked more on it without telling. I thought a heafty THANKS was what I owed MR.J

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Exclamation Clarification please

    I put in the code and.... i got the text box but it would keep the notes!
    Did you try all the buttons?
    If you type a note and 'SAVE' it, you can 'CLEAR' it on the display
    but it will not clear the earlier saved cookie unless you click on 'SAVE' again
    to over write the earlier note.

    Not being funny, but your reply did not indicate what exactly was happening.
    I'm not sure why you cannot 'get this code to work'.
    Do you get any errors in the JS control box of FF or a yellow '!' in the lower corner of IE?

  • #7
    New Coder
    Join Date
    Sep 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the code didn't do anything


    besides what other file?


    I use the Maxthon browser and javascript is enabled

  • #8
    New Coder
    Join Date
    Sep 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When i refresh it's not saved..
    even after i hit the save button

  • #9
    New Coder
    Join Date
    Sep 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ---LOCKED---

    i found it

  • #10
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts
    What was your solution?

  • #11
    New Coder
    Join Date
    Sep 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Today I tried the code again and seems to be working fine.

    My solution before was a new code.
    Now that code isn't working.


    The reason the code above didn't work is because I didn't save one file as globalcookie.js

    Another thing:
    The Save button saves the note
    Clear deletes it from the box but doesn't remove the cookie.
    Delete Removes the cookie completely.
    Display shows it.
    What does get note do?
    Last edited by hiddenbox; 06-26-2007 at 06:47 PM. Reason: Added Question


  •  

    Posting Permissions

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