bigheadedd Posted September 2, 2010 Share Posted September 2, 2010 Hi, I'm trying to come up with a simple solution to change the background colour of the page, but ideally without reloading the page. I have three links at the bottom of the page 'White', 'Black', 'Red' etc etc.. I then have three stylesheets respectively (white, black red). What I need is, when clicked on, it refreshes the page but loads in those stylesheets. Ideally i'd like to do this without index.php?colour=white As i'm trying to avoid people from directly seeing the inputs. I'd then store the value of the colour in a session and call it that way. Bit stuck on this one! Any help would be hugely appreciated Thanks Edd Quote Link to comment Share on other sites More sharing options...
cags Posted September 7, 2010 Share Posted September 7, 2010 It's not exactly what you were asking for, but as I came across it recently and it seems fairly apt I thought I'd share it... http://net.tutsplus.com/tutorials/javascript-ajax/jquery-style-switcher/ Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 8, 2010 Share Posted September 8, 2010 This should get you started. I am using sessions and a switch statement, no javascript needed Let me know if you need help, cheers! <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <?php $_SESSION['color'] = $_POST['color']; // color cases switch ($_SESSION['color']) { case 'white': echo '<link href="css/white.css" rel="stylesheet" type="text/css" />'; break; case 'green': echo '<link href="css/green.css" rel="stylesheet" type="text/css" />'; break; case 'blue': echo '<link href="css/blue.css" rel="stylesheet" type="text/css" />'; break; } ?> <title>color tester</title> </head> <body> <h1>bla bla bla h1</h1> <h2>dadadadada h2</h2> <h3>nanananana h3</h3> <p>p p p p p p p </p> <p>herunder is a color chooser</p> <form action="styleswitcher.php" method="post"> <select name="color"> <option value="white">white</option> <option value="blue">blue</option> <option value="green">green</option> <input type="submit" value="change color" name="submit" /> </select> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 8, 2010 Share Posted September 8, 2010 hmm maybe this is even cleaner: <?php $_SESSION['color'] = $_POST['color']; echo '<link href="css/'.$_SESSION['color'].'.css" rel="stylesheet" type="text/css" />'; ?> Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 8, 2010 Share Posted September 8, 2010 oops i didnt notice this was the ajax forum. Well if you apply the ajax stuff here and use my script it should work. cheers! Quote Link to comment Share on other sites More sharing options...
bigheadedd Posted September 8, 2010 Author Share Posted September 8, 2010 Thanks for the replys guys! I ended up going with forms & sessions in the end and it works pretty well! Going to add in some ajax as I've got the php/javascript working now, so should be relatively straight forward. Again, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.