View Full Version : End-User Options - Multi-Choice background color using Javascript

29 Dec 2008, 16:25
Multi-Choice background color using Javascript

Just a quickie here to give your members a choice of what color to display for the forum Background.

I quickly bought this together as a result of this request here http://www.vbulletin.org/forum/showthread.php?t=200086

Firstly, you need to save this code as a Javascript so copy it to your notepad and save it as "Backcolor.js"

function change_it() {

if (document.getElementById && document.createTextNode) {

var new_color = "";
var color_sel = document.getElementById("change_bg").value;
color_sel *= 1;

switch (color_sel) {
case 0 : window.alert("Please select a color."); return false;
case 1 : new_color = "#FFFF00"; break;
case 2 : new_color = "#3333FF"; break;
case 3 : new_color = "#009900"; break;

document.body.style.backgroundColor= new_color;
return false;



then you upload the backcolor.js file to same directory as the Web page on which you will use the script (ideally your Forum Root)

Then enter the code below, between the <body> and </body> tags where you want the select box and button to appear, ideally in the footer or header templates

As an example i saved it to the end of my header template, see the pictures ;)

<form action="#" onsubmit="return change_it();">
<select name="change_bg" id="change_bg">
<option selected="selected" value="0">Select Background</option>
<option value="1">Yellow</option>
<option value="2">Blue</option>
<option value="3">Green</option>
<input type="submit" value="Change Color" />
<script type="text/javascript" src="backcolor.js"></script>

What that will do is give your users a dropdown box with a Change Color button ( for the english spelling please change the above code here <input type="submit" value="Change Color" /> )

i've done this very basic, but you can change the colors in the backcolor.js file just change the case 1, 2 and 3 options with a new hex color #FFFFFF

You need to change the hex values to the colors that you choose for your site, in the javascript file (Hex numbers) and then with the template code (The color names)

You can get a nice selection of hexcolors here http://www.december.com/html/spec/colorsafe.html

This is what you get, Mind you it won't work well on my forum as its fluid, but it'll work well with fixed forums


Remember you can change these colors, I've just done 3 as an example, But you can add as many as you want and with millions of combinations by using a color Hex chart.

Have Fun


29 Dec 2008, 16:37
:D Reserved :up:

29 Dec 2008, 23:31
Will the color remain on subsequent visits? Is it stored in a cookie or anything? How about some how making it based off a profile field so it stores it in the user table?

01 Jan 2009, 14:05
Tried, and it works when I click on 'change color'. But when I load another page the new bg color return the default one.

01 Jan 2009, 15:50
There is a way of doing this, i'm just waiting for an email and i'll update the code ;)

06 Jan 2009, 22:25
Is there any news, UKBusinessLive?

11 Jan 2009, 09:06
Didn't really work on my forum.... :erm:

11 Jan 2009, 09:11
It seems to onllt work on the index page, I need to get a more experianced coder to take a look at the code, bear with me i'm working on this :cool:

27 Jan 2009, 12:57
I would suggest making a profile field

so the user can change the background look, in their profile or in the navbar.

27 Jan 2009, 17:33
I wonder if we could use this to change styles without reloading :D

28 Jan 2009, 23:05
Is there any news, UKBusinessLive?

Same here. VB 3.8.1.

Also I"d like to find out on how to change the "page background".

05 May 2009, 21:27
is this stuff still working :S

or there is any other mod for this?.. i remember there was a mod for the colors just like vb.org has

05 May 2009, 21:57
is this stuff still working :S

or there is any other mod for this?.. i remember there was a mod for the colors just like vb.org has

here it is rob