views:

41

answers:

2

Please note this is just an example:

<img src="img/normal-font.png" onclick="javascript:document.body.style.fontSize = '13px';" /> &nbsp; 
<img src="img/medium-font.png" onclick="javascript:document.body.style.fontSize = '14px';" /> &nbsp; 
<img src="img/large-font.png"onclick="javascript:document.body.style.fontSize = '15px';" />

The body text does indeed enlarge if I choose one of them, but what I like to include is remembering what option you've chosen by reading cookies.

In fact, I have no experience in creating cookies in JS, only in PHP. Could someone come up with an example of how to make cookies the simpliest way remembering my option, but whenever someone clicks another one, it should get rid of the cookie that was last set, e.g. Cookie value has 15px, then should update it or remove it with a new cookie with a new value of 13px and so on.

Thanks :)

A: 

This might Help: QuirksMode Javascript cookies reference.

Babiker
A: 

you can set and get the cookie values from javascript in the same way you do in php.

you can use the following two methods for your help.

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

have a look into this page for more details.

Elangovan