How to align the value in a text box using javascript?

How to align the value in a text box using javascript?

I found various methods to do it on google, but only one of them worked for me. Hence I decided to write a post on this.

function mytest3() {
// This works in both IE and chrome.

// Not working.
// document.getElementById("y1").style="text-align:right";

// Following works in Chrome (But not in IE)
// document.getElementById("y1").setAttribute("style", "text-align:right");


Well, for more information why the other two options were not working.
Please have a look at the following URL under section Text Properties

Another good link to study is

Well, if you like to use jquery and achive the same thing.

<title&gtjQuery demo
<script type="text/javascript" src="jquery.js" language="javascript"&gt



Another very good website for learning javascript is,html,live

About Vineet Verma

Developer/Blogger/Gamer/Lazy Couch Potato...:P Need PDF Books: Knowledge Base
This entry was posted in HTML. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s