Click to See Complete Forum and Search --> : cookie help


chadypu
08-12-2003, 10:27 AM
i am creating a stylesheet picker and so far i have the stuff that changes the stylesheet... now i am just gonna write a cookie so that i can use this stylesheet on every page
here is what i have so far


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT>
//the cookie functions
//--------------------
function setredcookie()
{

}
//--------------------
//the styles
function redwhite()
{
with (document)
{
write('<title>Chadypu.com||Red and White</title>')
write('<style>')
write('BODY {Background:#CC0000; color:white}');
write('A:link {color:blue;}');
write('A:active {font-size:h4; text-decoration: underline}');
write('A:Visted {color:purple;}');
write('</style>');
write('<img src="../Images/Banner1.jpg">')
write('<BR>hello');
}
}
function bluewhite()
{
with (document)
{
write('<title>Chadypu.com||Blue and white</title>')
write('<style>')
write('BODY {Background:#6633FF; color:white}');
write('A:link {color:red;}')
write('A:active {text-decoration: underline}');
write('A:Visted {color:purple;}');
write('</style>');
write('<img src="../Images/Banner2.jpg">')
write('<BR>hello');
}
}
//--------------------
</Script>
</head>

<body bgcolor="#ffff00" text="#ff0000">


<h1>What theme would you like?</h1>
<A Href=javascript:redwhite()>White on Red</A><br>
<A Href=javascript:bluewhite()>White on Blue</A><br>
<A Href=mailto:kissfanchad@hotmail.com>I would like another style</A>
<b>
<br>test text
<br>[test]
</b>

</body>
</html>

as you can see i didnt get too far on function setredcookie
can someone atleast get me pointed in the right direction on what to do
i have never done anything with cookies before
all i wanna know is how i set the cookie and how i retrieve it
if someone could write something that would be great

pyro
08-12-2003, 10:29 AM
Did you read over the stuff I linked you to last night? (http://forums.webdeveloper.com/showthread.php?s=&threadid=15220) You still haven't been able to write any code??

chadypu
08-12-2003, 10:32 AM
yeah still having trouble
im gonna eat breakfast and then take another stab at it

metrosoccer12
08-12-2003, 10:33 AM
to start:
<A Href=java script:redwhite()>White on Red</A><br>

should be

<A Href=javascript:redwhite()>White on Red</A><br>

same with the other color

pyro
08-12-2003, 10:36 AM
You could do something like this:

function setredcookie() {
expdate = new Date()
expdate.setFullYear(expdate.getFullYear() + 1);
document.cookie = "red=true; expires=" + expdate.toGMTString();
}That will set a cooke named red that will expire in one year...

metrosoccer12
08-12-2003, 10:40 AM
i was just trying out ur script it doesnt seem to work it just makes a new page with the red and the banner on it... thats defeating the reason to use it if u want to do that cause u could just link to a page with red etc..

chadypu
08-12-2003, 10:40 AM
in the function to set the cookie where do i put the data i want saved in the cookie

function redwhite();with (document);write('<title>Chadypu.com||Red and white</title>');write('<style>'); write('BODY {Background:#cc0000; color:white}'); write('A:link {color:red;}');write('A:active {text-decoration: underline}'); write('A:Visted {color:purple;}'); write('</style>');write('<img src="../Images/Banner1.jpg">');

thats what i want saved in the cookie

in my files on my comp there is no space inbetween the javascript... meh whatever

chadypu
08-12-2003, 10:41 AM
soccer... thats what i want, im using that for testing, what im gonna do is put this in a 0 by 0 frame and in the other frame have the page

chadypu
08-12-2003, 11:07 AM
function setredcookie()
{
var curCookie = redstyle + "=" + escape(function redwhite();with (document);write('<title>Chadypu.com||Red and white</title>');write('<style>'); write('BODY {Background:#cc0000; color:white}'); write('A:link {color:red;}');write('A:active {text-decoration: underline}'); write('A:Visted {color:purple;}'); write('</style>');write('<img src="../Images/Banner1.jpg">'););
expdate = new Date()
expdate.setFullYear(expdate.getFullYear() + 1);
document.cookie = curCookie;
alert('cookie has been set, i think :p')
}

thats what i have right now, its not working

chadypu
08-12-2003, 12:28 PM
bump

pyro
08-12-2003, 12:42 PM
I would so totally not do it that way. When I did it, I used PHP to set the correct stylesheet, but if you want the javascript way of doing it, I would use http://www.alistapart.com/issues/126/ (or I might create my own method...)