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?

27 of 29 people (93%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I center text in a text field?

May 21st, 2000 17:32
Martin Honnen,


NN6 and IE4+ support css to do that

<INPUT TYPE="text" STYLE="text-align: center;" SIZE="20" VALUE="Kibo">

Note that NN4 is centering the whole input field with this setting so 
you need to document.write the INPUT field:
  var input =
    '<INPUT TYPE="text" SIZE="20" VALUE="Kibo"';
  if (document.all || document.getElementById)
    input += ' STYLE="text-align: center;"';
  input += '>';
  document.write(input);