user3259282 user3259282 - 1 year ago 52
Javascript Question

Input box to change the background color of a webpage using javascript

On my web page I have JavaScript script that changes the background color. My HTML is:

<a href="#" onclick="javascript:changeBGC('#FFFFFF')">White</a>

My Javascript function is:

function changeBGC(color){
document.bgColor = (color);

How can I change the color of the background getting the color from an
box instead of putting a predefined value?

Answer Source

Here's a FIDDLE

<input id="color" type="text" onKeyUp="color();">

function color() {'color').value;