I created a notepad of sorts using Javascript (using code for cookies from http://www.quirksmode.org/js/cookies.html). It works fine.. except that it cannot save multiple lines.
In Firefox and Opera, when the value of the textarea is changed to the cookie value, only the first line is displayed (before any line breaks). In IE, each line break is simply replaced by two underscores ("__"), so all lines can be seen but they are on a single line.
Is there any solution to this problem? My Javascript and HTML code is below.
Any help would be greatly appreciated.
In Firefox and Opera, when the value of the textarea is changed to the cookie value, only the first line is displayed (before any line breaks). In IE, each line break is simply replaced by two underscores ("__"), so all lines can be seen but they are on a single line.
Is there any solution to this problem? My Javascript and HTML code is below.
PHP Code:
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
function writeNotepad() {
var notes = unescape(readCookie('notepad'));
if (notes) {
document.calc.notepad.value = notes;
}
}
PHP Code:
<td colspan="2">
<textarea name="notepad" id="notepad" rows="5" cols="40"></textarea>
</td>
</tr>
<tr>
<td><input type="button" value="Save" onclick="createCookie('notepad',document.calc.notepad.value,7)" /></td>
<td><input type="button" value="Open" onclick="writeNotepad()" /></td>

Comment