View Full Version : How to let a user change the background color?

01-30-2010, 12:22 AM
Hello, I am trying to set it up on my website that lets users change the color and other styles of certain areas, and then preview those changes in another window. Right now I am just trying to test a little piece of it to see how it works but I'm not having any luck.

This is my javascript:

function Avatar() {
var bgColor1 = document.getElementById("bgColor1")
var profilePic = document.getElementById("profilePic")

profilePic.style.bgColor = bgColor1.value

And this is my html:

<input type="text" id="bgColor1" maxlength="6" size="8" class="colorpickerField2" onchange="Avatar(this.value" >
<br />
<div id="profilePic"></div>

This text box has a drop down color picker that I implemented so that my user can choose their color, http://www.eyecon.ro/colorpicker/
(The color picker works but its just that it doesnt change the color of the div) If anyone knows a way that I could get this to work, please tell me!!! :confused:

01-30-2010, 11:59 PM

function Avatar() {
var bgColor1 = document.getElementById("bgColor1");
var profilePic = document.getElementById("profilePic");
profilePic.style.backgroundColor = bgColor1.value