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

Seb Barre sebastien at oven.com
Wed Oct 18 09:47:08 CDT 2000


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?

That's a good question.  I'm kinda shocked that it's not built into the 
HTML rendering as an attribute, but I guess I've never had the need for it 
so I never noticed.

This kind of hack is probably the best solution you'll get.  You will have 
to play around with the maxlength value for the padding (since spaces don't 
take up as much width as characters) and manually pad the boxes once they 
have info entered into them.   It's ugly, I know..  but I looked it up 
myself and I don't see any support for right-aligned input fields anywhere..

 >
 > <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;
 > }
 > </script>
 >
 > (....)
 >
 > <form name=test>
 > <input type=text name=tfield size=10 maxlength=10 onChange="return 
reformat(this);">
 > </form>
 >

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





More information about the thelist mailing list