Jump to content

Changing Background of Click of Text Fields


Guest bbolman

Recommended Posts

Guest bbolman

I've seen this done a lot, for example, where when you click in a field to search, the background of the field brightens a little, or something along these lines. I'm a little new to web dev and everything so pardon me if this is the wrong area for this question, but how would I get it so that for example: a field is normally red, but when you click in it to type, it becomes white again. It must be possible, I just can't figure out how. Thanks in advance.

Link to comment
Share on other sites

It's done with CSS, javascript, and HTML DOM. Something like this:

<html><head><style type="text/css">input.Required { background-color: #cc0000; }input.Selected { background-color: #ffffff; }</style></head><body><input type="text" class="Required" onfocus="this.className='Selected';" onblur="this.className='Required';" /><input type="text" class="Required" onfocus="this.className='Selected';" onblur="this.className='Required';" /><input type="text" class="Required" onfocus="this.className='Selected';" onblur="this.className='Required';" /></body></html>

Check out these links for more info:http://www.w3schools.com/htmldom/dom_obj_event.asphttp://www.w3schools.com/htmldom/prop_body_classname.asp

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...