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
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help! Select drop down to change colour scheme

    HELP! I will try to make this as short and painless as possible. I have a select drop down menu that allows a user to change the colour scheme of my webpage ultimately by using .setAttribute and changing the "href" attribute to locate a different style sheet. Here is my problem, when I click a link to go to another page within my site it reverts back to the original colour scheme, I am not sure how exactly I would get my script to remember what the selectedIndex is on the previous loaded page. Here is my javascript:

    "var styleSheet=document.getElementById("stylez");
    var checker;

    function changeColour() {
    if(document.getElementById("colour").selectedIndex==1){
    checker=1;
    styleSheet.setAttribute("href", "styles/styles.css");
    }
    if(document.getElementById("colour").selectedIndex==2){
    checker=2;
    styleSheet.setAttribute("href", "styles/styles02.css");
    }
    }


    if(checker==1) {
    styleSheet.setAttribute("href", "styles/styles.css");
    }
    if(checker==2) {
    styleSheet.setAttribute("href", "styles/styles02.css");
    }"


    The if statements at the end there are my attempt to get it to load the correct colour scheme, but what I am thinking is that the variable checker is equal to null because it is redeclared when the script is loaded on a new HTML page.

    How can I fix this?

    All comments and help are much appreciated.

  • #2
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And thanks ahead of time!

  • #3
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://www.andrew-horn.com/ <--This is the page in reference to

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,692
    Thanks
    25
    Thanked 657 Times in 656 Posts
    You need to set a cookie and read it for each user. This link may help: http://www.perlscriptsjavascripts.com/js/cookies.html
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    ... using query strings would be the alternative, for people who have cookies disabled


  •  

    Posting Permissions

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