[thelist] JS Question - Right align text in input box??

Seb Barre sebastien at oven.com
Wed Oct 18 10:49:21 CDT 2000

At 10:44 AM 10/18/2000 -0400, you wrote:
>At 10:05 AM 10/18/2000 -0500, you wrote:
>>      Hello all,
>>      One of my co-workers need to have his input box text right aligned.
>>      He is doing a spreadsheet type page and it looks wierd with the
>>      numbers left aligned.  I have looked at all my bookmarked JS code
>>      sources and couldn't find anything.
>>      Can anyone help with this?

Bah.  In the end this will work better for you, so ditch my last 
suggestion.  If you re-click in the field after it's been formatted, the 
formatting will be removed so you can edit it, and then it reformats when 
you move on.   Less messy for the user.

<script language="Javascript">

function reformat(field) {
         var padding = field.maxLength - field.value.length;
         for (i = 0; i < padding; i++) {
                 field.value = " " + field.value;
         return true;

function unformat(field) {
         var content = field.value
         var spaces = content.lastIndexOf(" ");
         field.value = content.substring(spaces+1,field.value.length);
         return true;

<form name=test>
<input type=text name=tfield size=10 maxlength=10 onBlur="return 
reformat(this);" onFocus="return unformat(this);">

So again, once you have the field set to the length you want, play with the 
maxlength (increase it) until the number lines up properly.

--- -- -
Seb Barre - sebastien at oven.com
OVEN Digital Toronto
Work: 416-595-9750 x 222
Mobile: 416-254-5078

More information about the thelist mailing list