• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

HTML problem with cookies...

Ichinisan

Lifer
I'm experimenting with cookies and I want to store the content of a textarea object. It's multi-line. When I store and retrieve the cookie, I get only the first line from the original textarea.

createCookie:

Code:
function createCookie(cookiename,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=cookiename+"="+value+expires+"; path=/";
}

readCookie:

Code:
function readCookie(cookiename){
	var nameEQ=cookiename+"=";
	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 "";
}

Can I make it so createCookie preserves line breaks in the value?
 
Use escape codes for hard returns, for example:
- change any "~" to "~~"
- change any \r\n or \r or \n to "~"

Be careful about limits of cookies, different browsers might truncate any one cookie at some magic number like 500 characters or 1020 characters.
 
Not sure what you are trying to do, but remember you can not trust any of the data in the cookie when you get it from the client.

Just because you tell me what data to store in a cookie doesn't mean I will actually do it and then return the same data.
 
It's a form I will use for myself and I can bring up any of my last 5 submissions to make minor changes and re-submit.
 
Back
Top