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

change the style/color of a disabled component

 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do I change the style/color of a disabled input component like text. A input component is grayed out by default when it's disabled. For example, I want to change the text color of <input type="text" value="hello" disabled> . I tried setting attribute style="color:black" but it doesn't work. Any idea?
thanks
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set it to readOnly="true" to be able to style the element.

Eric
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I tried:
<input type="text" name="description" class="textarea1" readonly="false" disabled>and
<input type="text" name="description" class="textarea1" readonly="true" disabled>
and .textarea1{
color: black;
background-color:blue;
}
the color does not change to black, the blackground-color works ok. This is true regardless wheather readonly is set to true or false.
Is there a way to change the disabled text color?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you do not use disabled at all, you only use the read only property.
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks that helps. But what about for checkboxes? I set readOnly to true for checkboxes but i can still change them.
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when u handle the event first, enable the element do what you want with it and then disable it again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic