Log in

View Full Version : style changer help



Nate1n22
04-28-2010, 02:28 AM
I have a style changer and I want it so when someone selects the color they want, it stays saved.
HTML Code:

<script type="text/javascript">
function changeStyle(href){
if(href){
document.getElementById("style-reset").href = "layout/css/reset.css";
document.getElementById("style").href = "style.css";
document.getElementById("style-variation").href = href;
}
else{
alert("No stylesheet entered.");
}
}
</script>
And the dropdown box with the different colors:
HTML Code:

<li><a href="#" onclick="changeStyle('layout/css/style1.css');">Blue</a></li>
<li><a href="#" onclick="changeStyle('layout/css/style2.css');">Black</a></li>
<li><a href="#" onclick="changeStyle('layout/css/style3.css');">Green</a></li>
<li><a href="#" onclick="changeStyle('layout/css/style4.css');">Purple</a></li>
<li><a href="#" onclick="changeStyle('layout/css/style5.css');">Red</a></li>
<li><a href="#" onclick="changeStyle('layout/css/style6.css');">Olive</a></li>
__________________

Beverleyh
05-08-2010, 11:11 PM
You need cookies. I'm not that great with writing javascript from scratch but maybe you could look at this jQuery stylesheet switcher with cookie save functionality: http://www.cssnewbie.com/simple-jquery-stylesheet-switcher/

The demo page has the copy-and-paste source code in full: http://www.cssnewbie.com/example/stylesheet-switcher/
Just make sure you also download jQuery: http://jquery.com/
And the cookie plugin that the stylesheet switcher uses: http://plugins.jquery.com/project/Cookie
(and remember to change the script paths in the head to point to them)