Blasttrash Blasttrash - 1 year ago 107
CSS Question

Why is this javascript code to change background color not working?

I want to change the background color ,when the user clicks the button, to the color he/she selected from the dropdown. Here's the html and javascript code for it.

<!DOCTYPE html>
<title>Change Color Demo</title>
function changeColor(){
var selColor = document.getElementById("selColor");
var color = selColor.value; = color;
<form action="">
<select id="selColor">
<option value="FFFFFF">White</option>
<option value="FF0000">Red</option>
<option value="FFCCFF">Orange</option>
<option value="FFFF00">Yellow</option>
<option value="00FF00">Green</option>
<option value="0000FF">Blue</option>
<option value="663366">Indigo</option>
<option value="FF00FF">Violet</option>

<input type="button" value="change color" onClick="changeColor()"/>

But it's not working for some reason. Please help.


Answer Source

CSS colours using hex to represent RGB must start with a # character.