Javascript Cookies

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

dudeking

Thread Starter
Joined
Feb 7, 2007
Messages
483
This is a script to change the theme of my site. But unfortunately it dosnt work.....

PHP:
<?php
			if(isset($_COOKIE["colorscheme"])){
				if($_COOKIE["colorscheme"] == "black"){
					echo '<link href="/style/black.css" rel="stylesheet" type="text/css" />';
				}elseif($_COOKIE["colorscheme"] == "white"){
					echo '<link href="/style/black.css" rel="stylesheet" type="text/css" />';
				}
			}else{
				echo '<link href="/style/black.css" rel="stylesheet" type="text/css" />';
			}
			echo '<link href="/style/all.css" rel="stylesheet" type="text/css" />';
		?>
Code:
<script type="text/javascript">
			//Colour Scheme Cookie Set
			function setcolorscheme(){
				sitetheme = getCookie(colorscheme){
					if(sitetheme == black){
						function setCookie(colorscheme,white,expiredays){
							var exdate=new Date()
							exdate.setDate(exdate.getDate()+expiredays)
							document.cookie=colorscheme+ "=" +escape(value)+
							((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
						}
					}
					if(sitetheme == white){
						function setCookie(colorscheme,black,expiredays){
							var exdate=new Date()
							exdate.setDate(exdate.getDate()+expiredays)
							document.cookie=colorscheme+ "=" +escape(value)+
							((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
						}
					}
				}
			}
		</script>
HTML:
<a onclick="setcolorscheme()" style="width:50px; height:50px; display:block;" href="#">
				</a>

Edit:

http://dudeking.co.uk its set to the button in the top right which says white and has a down arrow
 
Joined
Mar 27, 2007
Messages
46
Can you explain the problem a little bit more? What error do you get, if any?

Is the white and black cookie supposed to link to the same stylesheet, because your code loads black.css on all instances

PHP:
if($_COOKIE["colorscheme"] == "black"){
                    echo '<link href="/style/black.css" rel="stylesheet" type="text/css" />';
                }elseif($_COOKIE["colorscheme"] == "white"){
                    echo '<link href="/style/black.css" rel="stylesheet" type="text/css" />';
                }
            }else{
                echo '<link href="/style/black.css" rel="stylesheet" type="text/css" />';
 

MMJ

Guest
Joined
Oct 15, 2006
Messages
3,625
I could point out the errors in your code but the way you are doing things aren't that smart.

How does the php code get executed? The setcolorscheme() function doesn't refresh the page.
 

dudeking

Thread Starter
Joined
Feb 7, 2007
Messages
483
Well basicly nothing happens, no cookie is set and the style sheet doesnt change.

Thank you for pointing out that both stylesheets are the same. I'll change that now!

Well, I have never really done any Javascript before espicly nothing this advanced. I have just presumed much of the syntax to be the same as php which is wrong. Should I use all javascript or should I some how make that function refresh the page?
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top