Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Input Textfield Background Color When the Cursor Is There

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jinjing Cao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remove "___" in "onblur___", the system don't allow this word.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prithiraj Sen Gupta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me answer my own question.

IE 6, we may have to use JavaScript

In IE7 and modern browsers such as Firefox and Opera:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic