change form fields onfocus and onblur

Hi - I'd like to change the border and background color of form fields when the user clicks on them, or tabs to them.  Then when the user clicks away,  the form field reverts to its previous look.  
Can someone please show me how this is done?
TIA your input.
Who is Participating?
Maybe you can use this:
function toggleFocus(theElement) {
	if ( == "lightgrey" ) { = "white"; = "black";
	else { = "lightgrey"; = "red";
#myText {
	border: 1px solid #000;
<input name="myText" id="myText" onfocus="toggleFocus(this);" onblur="toggleFocus(this);>

Open in new window

dzash2000Author Commented:
JoachimMartin - this works on text fields.  
I guess I should have stated form elements instead of form fields.
Is it possible to make it work just as well on other types of form elements - like select lists, check boxes?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.