Nayias
12-25-2003, 05:00 PM
Hey all, im trying to make a script that change the background color of a tekstfield when you type a number in that field.
this is the code i have till now:
function changetocolor(field)
{
var hello = new Array();
hello[0] = "blue";
hello[1] = "red";
hello[2] = "green";
hello[3] = "yellow";
hello[4] = "orange";
hello[5] = "black";
hello[6] = "purple";
hello[7] = "pink";
var color_number = parseInt(field.value);
field.style.background-color=hello[color_number];
}
then the user should type a color between 0 and 7,
so if the user types 4 the background color of the tekstfield should change to "orange".
I use the onChange event handler to call the function:
<input type="tekst" onChange="changetocolor(this)" >
im not sure if you can change the background color with: background-color
so i tried this:
backgroundColor
but that didnt work too.
can someone tell me why it doesnt work?
thx
this is the code i have till now:
function changetocolor(field)
{
var hello = new Array();
hello[0] = "blue";
hello[1] = "red";
hello[2] = "green";
hello[3] = "yellow";
hello[4] = "orange";
hello[5] = "black";
hello[6] = "purple";
hello[7] = "pink";
var color_number = parseInt(field.value);
field.style.background-color=hello[color_number];
}
then the user should type a color between 0 and 7,
so if the user types 4 the background color of the tekstfield should change to "orange".
I use the onChange event handler to call the function:
<input type="tekst" onChange="changetocolor(this)" >
im not sure if you can change the background color with: background-color
so i tried this:
backgroundColor
but that didnt work too.
can someone tell me why it doesnt work?
thx