Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with template/style changer

    Im using this code for a style changer


    function setActiveStyleSheet(title) {
    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
    a.disabled = true;
    if(a.getAttribute("title") == title) a.disabled = false;
    }
    }
    }

    function getActiveStyleSheet() {
    var i, a;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
    }
    return null;
    }

    function getPreferredStyleSheet() {
    var i, a;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
    && a.getAttribute("rel").indexOf("alt") == -1
    && a.getAttribute("title")
    ) return a.getAttribute("title");
    }
    return null;
    }

    function createCookie(name,value,days) {
    if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
    }

    function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }

    window.onload = function(e) {
    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);
    }

    window.onunload = function(e) {
    var title = getActiveStyleSheet();
    createCookie("style", title, 365);
    }

    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);


    In my head section i have this
    <link rel="stylesheet" type="text/css" href="tcw.css" title="default"/>
    <link rel="alternate stylesheet" type="text/css" href="tcw1.css" title="tcw1"/>

    Im supposed to be using HREF's to make this work.
    <a href="#"
    onclick="setActiveStyleSheet('default'); return false;">change style to default</a><a href="#" onclick="setActiveStyleSheet('tcw1'); return false;">change style to paul</a>

    and it does work. However, how do i convert these to use DROPDOWN's instead of hrefs?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    <select onchange="setActiveStyleSheet(this.options[this.selectedIndex].value)">
    <option value="default">Default Style</option>
    <option value="tcw1">Paul's Style</option>
    </select>

  • #3
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perfect...thanks!!
    Last edited by chuggs93; 01-09-2004 at 02:15 PM.

  • #4
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, also...I have this



    code:--------------------------------------------------------------------------------
    <select class="dropdown" onchange="setActiveStyleSheet(this.options[this.selectedIndex].value)">
    <option>- -Select A Style- -</option>
    <option value="New V1">- -New V1- -</option>
    <option value="Original_White">- -Original w/White- -</option>
    <option value="Original_Gold">- -Original w/Gold- -</option>
    </select>--------------------------------------------------------------------------------


    and it works perfect, except for when you select the --Select a style-- option, my site turns into nothing but a printable version. all the css stuff is gone. its weird. Is there a way to set that option so that NOTHING happens when it is selected??

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    <select class="dropdown" onchange="if (this.selectedIndex>0) setActiveStyleSheet(this.options[this.selectedIndex].value)">


  •  

    Posting Permissions

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