faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

120 of 139 people (86%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

(How) can I set the background color of a text field/text area?

Mar 8th, 2000 14:04
Martin Honnen,


Only IE4/5 (and likely NN6) support that using css statically or the 
style object dynamically.
CSS:
  <INPUT TYPE="text" STYLE="background-color: red;">
JavaScript:
  var field = document.formName.fieldName;
  if (field.style) // dynamic style scripting possible
    field.style.backgroundColor = 'red';
Color values in css can also be specified as triples e.g.
  <INPUT STYLE="background-color: rgb(255, 0, 0)">
respectively
    field.style.backgroundColor = 'rgb(255, 0, 0)';
Using
  #FF0000
might also work.