Results 1 to 2 of 2

Thread: style changer help

  1. #1
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default style changer help

    I have a style changer and I want it so when someone selects the color they want, it stays saved.
    HTML Code:
    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:
    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>
    __________________

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    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-jque...heet-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)
    Last edited by Beverleyh; 05-08-2010 at 11:17 PM. Reason: jQuery links added

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •