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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Allow Javascript input choice to hold on new page load

    I currently have a JavaScript code (that is working) to change the background color of my page.

    However when the code does not hold the user's choice of background when on other pages of the site, or when reloading the page.

    The script is currently loaded onto my website at
    www.taylormccaslin.com

    Below is the color changing script:

    Code:
    <HEAD>
    <script language="JavaScript">
    
    var backColor = new Array();
    
    backColor[0] = '#9E0704';
    backColor[1] = '#D36100';
    backColor[2] = '#E8B900';
    backColor[3] = '#23671C';
    backColor[4] = '#000066';
    backColor[5] = '#6C4687';
    backColor[6] = '#B2B2B2';
    backColor[7] = '#000000';
    
    
    function changeBG(whichColor){
    document.bgColor = backColor[whichColor];
    }
    
    </script>
    </HEAD>
    <BODY>
    
    <!-- Color Bars -->
    <div id="element60" style="position: absolute; top: 12px; left: 125px; width: 875px; height: 20px; z-index: 9;">
    <a href="javascript:changeBG(6)"><IMG SRC="images/color_changer/b_white.gif" border="0"></a> 
    <a href="javascript:changeBG(0)"><IMG SRC="images/color_changer/b_red.gif" border="0"></a> 
    <a href="javascript:changeBG(1)"><IMG SRC="images/color_changer/b_orange.gif" border="0"></a> 
    <a href="javascript:changeBG(2)"><IMG SRC="images/color_changer/b_yellow.gif" border="0"></a> 
    <a href="javascript:changeBG(3)"><IMG SRC="images/color_changer/b_green.gif" border="0"></a> 
    <a href="javascript:changeBG(4)"><IMG SRC="images/color_changer/b_blue.gif" border="0"></a> 
    <a href="javascript:changeBG(5)"><IMG SRC="images/color_changer/b_purple.gif" border="0"></a> 
    <a href="javascript:changeBG(7)"><IMG SRC="images/color_changer/b_black.gif" border="0"></a></div>
    
    
    <!-- Pick Your Color -->
    <div id="element61" style="position: absolute; top: 10px; left: 10px; width: 112px; height: 15px; z-index: 10;"><div><font face="'Bookman Old Style', 'Times New Roman', Times, serif" color="#FFFFFF" class="size10 BookmanOldStyle10">Pick Your Color :<br></font></div></div>
    
    </BODY>

    Is there a way to make this choice hold?
    I have been looking into the setActive() fuction. And I have also thought about using a OnClick code to write a cookie containing the background color information for each color and then having an OnLoad function to check for a cookie, if present use that background color.

    Please help! I have been at this for days and I just don't know how to approach it. I am also a very armature coder, so my knowledge of JavaScript is not that vast.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by Taylor4484 View Post
    I currently have a JavaScript code (that is working) to change the background color of my page.

    However when the code does not hold the user's choice of background when on other pages of the site, or when reloading the page.
    As a client-side language, JavaScript can not store/write data. That means when the session is changed, all the modifies it could have done on a page are lost, except if data is previously sent to a data base via a server-side application. There might be also the cookie technique:

    http://www.w3schools.com/JS/js_cookies.asp
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Tags for this Thread

    Posting Permissions

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