PDA

View Full Version : Help me to get my cookies working.



Ashly Thompson
10-17-2011, 08:09 AM
Please someone help me.

I have created these cookies and want to resize text with two buttons. But I am wrong somewhere and can't think any more. text size is increasing and decreasing. but when I close the page and reopen it the default font is there.I want my preferred font size to be saved as cookies. Please help me.

thanks

this is my code..



<script type="text/javascript">

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

if (document.body.style.fontSize== ""){
document.body.style.fontSize ="1.0em";

}

document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
}

function setCookie (name) {
var Cookie
var resizetext
resizetext=bodyElement.value;
createCookie("resizetext",tresizetext, 365);
return false;

}
<script>







<lable> This text need to be big and small </label><br />
<Input type="button" value= "big text" onclick="resizeText(1)" />
<input type="button" value= "Small text"onclick="resizeText(-1)" />

vwphillips
10-17-2011, 01:34 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">

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 resizeText(multiplier,days){

if (document.body.style.fontSize== ""){
document.body.style.fontSize ="1.0em";

}

document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
createCookie('body',document.body.style.fontSize,days||-1);
}

function setCookie() {
if (readCookie('body')){
document.body.style.fontSize=readCookie('body')
}
}
</script></head>

<body onload="setCookie();" >
<lable> This text need to be big and small </label><br />
<Input type="button" value= "big text" onclick="resizeText(1,1)" />
<input type="button" value= "Small text"onclick="resizeText(-1,1)" />
</body>

</html>