Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-29-2010, 10:07 PM   PM User | #1
Taylor4484
New to the CF scene

 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Taylor4484 is an unknown quantity at this point
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.
Taylor4484 is offline   Reply With Quote
Old 07-30-2010, 01:46 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Tags
color changer, javascript, page load, support

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:21 AM.


Advertisement
Log in to turn off these ads.