• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to color a blank textfield

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using some JSP but I want a textfield colored red if it is blank. If this can be done in Javascript, please let me know. Any help is greatly appreciated.

Thanks.

-------code-----------
if the textfield has no value, color it red. if user inputs a value then take color out.

<td><input name="textfield1" type="text" size="30" value= "<%=N_ASDR1 %>"></td>
<td><input name="textfield2" type="text" size="30" value= "<%=N_ASDR2 %>"></td>
<td><input name="textfield3" type="text" size="30" value= "<%=N_ASDR3 %>"></td>
<td><input name="textfield4" type="text" size="30" value= "<%=N_ASDR4 %>"></td>
----------------------
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
{bear edit: removed example too full of errors to be useful. Niki feel free to re-post once you fix the problems]
[ October 03, 2005: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can color the background with the background-color CSS property.

For changing based upon whether the field is empty or not, you will need to establish event handlers on the text field to detect changes. The onchange handler itself will not be enough because it's not called on individual keystrokes. You'll need to also at least listen to onkeyup.

In the handler you can change the color of the background using CSS under Javascript control.

It's not foolproof however. I'm not sure how you can capture the field being emptied by a cut operation via the menu for example.

[ October 03, 2005: Message edited by: Bear Bibeault ]
[ October 03, 2005: Message edited by: Bear Bibeault ]
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic