aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Input Textfield Background Color When the Cursor Is There Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Input Textfield Background Color When the Cursor Is There" Watch "Input Textfield Background Color When the Cursor Is There" New topic
Author

Input Textfield Background Color When the Cursor Is There

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
How do I set the input textfield background color when that textfield is active? I mean when the cursor is in that textfield.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Answer these three questions:

1. How can you detect when the field has focus?
2. How can you detect when the field loses focus?
3. How can you change the background color of an element?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jinjing Cao
Greenhorn

Joined: Nov 15, 2005
Posts: 2
Try this example:
__________________________
<html> <head> <style> .inputBlur { background:#e9e9e9; border:1px none #FFFFFF; } .inputFocus { background:lightgreen; border:1px solid gray; </style> </head> <body> <input id='myinputbox' onfocus="dofocus();" onblur___="doblur();" class="inputBlur"> <script language=javascript> var inbox = document.getElementById('myinputbox'); alert(document.getElementById('myinputbox')); function dofocus() { inbox.className = 'inputFocus'; } function doblur() { inbox.className = 'inputBlur'; } </script> </body> </html>
__________________________
Jinjing Cao
Greenhorn

Joined: Nov 15, 2005
Posts: 2
remove "___" in "onblur___", the system don't allow this word.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

hi JiaPei Jen,

All hint are there in Bear post, if you know, how to do these task then no difficulty exists to achieve this.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Prithiraj Sen Gupta
Ranch Hand

Joined: Sep 13, 2006
Posts: 92
Hi,
I feel what Bear has written is enough.
He could have written two lines of answers instead of writing 3 questions. If Jen only copy and paste the codes he wont be going anywhere. It is better to start with hints so he will have something to cook in his mind.

Thanks & Regards

Prithiraj
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Let me answer my own question.

IE 6, we may have to use JavaScript

In IE7 and modern browsers such as Firefox and Opera:
 
 
subject: Input Textfield Background Color When the Cursor Is There