Javascript: Limiting string length in textbox

I am wetting my beak in the Javascript world and I learn something new every day. When I faced this problem of limiting the length of string that the user can enter in a textbox, Google failed to return a satisfying result. My co-worker told me about the amazing attribute maxLength that is available for textbox. Works like magic.

If you want to restrict the length to 50, then just add an attribute ‘maxLength’ like this:

<input id="myTextBox" type="text" name="myTB" maxLength=50>

If you want to do this in javascript using jquery, then you need to add this line in your js file:

$("#myTextBox").attr("maxLength", 50);

I wonder why Silvelright textbox does not have something similar. This is a very helpful attribute for developers, do you agree?


2 thoughts on “Javascript: Limiting string length in textbox

  1. Reply for post : “Javascript: Limiting string length in textbox”

    hi, can i place an ads on your blog ?
    Review my classified website :

  2. kc says:

    it doesnt work on my code

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

%d bloggers like this: