Forum Moderators: not2easy

Message Too Old, No Replies

textbox onfocus and onblur actions

change background color

         

pithhelmet

4:11 pm on Apr 26, 2004 (gmt 0)

10+ Year Member



Hi Everyone -

I am creating a data entry form and would like
to change the background color of the textbox when
the textbox becomes active, and change the color
back to white when the focus is moved from the
textbox....

I have the CSS setup - i am just not sure
on how to change the background when the
textbox receives focus...
(inline code please)

please advise

thanks
tony

birdbrain

5:02 pm on Apr 26, 2004 (gmt 0)



Hi there pithhelmet,

Welcome to these forums ;)

Try this...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>onfocus~onblur</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
</head>
<body>

<form action="">
<div>
<textarea rows="5" cols="20" onfocus="this.style.backgroundColor='#ff0000'"
onblur="this.style.backgroundColor=''"></textarea>
</div>
</form>

</body>
</html>

birdbrain

drbrain

5:23 pm on Apr 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



input[type="input"]:focus { background: red }

It'll only work on browsers that support attribute selectors and :focus, of course (not IE).