[thelist] using JS to alter background colour of form input

Dunstan Orchard dunstan at 1976design.com
Sun Mar 9 05:29:01 CST 2003


Hi there,

I have this little script that checks to see if a form field has been filled
in, and if not it alerts the user then puts focus back into that field.

e.g.

if (document.getElementById('FirstName').value == "")
	{
	alert("Please enter a value for the \"First name\" field.");
	document.getElementById('FirstName').focus();

	return (false);
	}

Is there any way I can also alter that form input's CSS background colour
using JS to draw their attention to it?

All the things I've tried, like:

document.getElementById('FirstName').style.background-color.value = "#d6d";

have no effect, or break the script.

I've searched all over the place and can't find anything either.

What would be the correct way of doing this? (I'd prefer not to have to
initially set background style attributes for each input if possible.)

Thanks very much,

- dunstan

---------------------------
Dorset, England
http://www.1976design.com/
http://www.orchard.it/
http://www.maccaws.org/



More information about the thelist mailing list