View Full Version : Javascript:Notes

10-28-2006, 01:13 AM
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"..


Enter your notes:

Remember to pick up the "whatever"...


Come back

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

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......

10-28-2006, 03:53 AM
You can use or modify this:


// 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"; }

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

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

<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>
<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.)

Keep in mind that 'cookies' cannot be shared at different computers.
Only keeps the 'notes' on the calling computer.

10-28-2006, 04:31 AM
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!

10-28-2006, 05:21 AM
Two questions:
1. Did you save BOTH files to the same directory?
2. What browser are you using and is your javascript enabled?

10-28-2006, 05:41 AM
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

10-28-2006, 03:12 PM
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?

10-28-2006, 06:08 PM
the code didn't do anything :(

besides what other file?

I use the Maxthon browser and javascript is enabled

10-28-2006, 06:24 PM
When i refresh it's not saved..
even after i hit the save button

10-29-2006, 01:03 AM

i found it :)

10-30-2006, 06:03 AM
What was your solution?

06-26-2007, 07:45 PM
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?