validating textarea using javascript/dhtml

March 4, 2008 at 2:45 am 7 comments

So many times we need to validate textarea to limit users from entering more charachters

Here is the code which is tested  in IE for validating textarea for 255 charachters.

/*copy this code in head tag */

<script language = “Javascript”>
* Author : suresh kumar

function taLimit(taObj) {
if (taObj.value.length==maxL) return false;
return true;

function taCount(taObj,Cnt) {
if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
if (objCnt) objCnt.innerText=maxL-objVal.length;
return true;
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval(“document.” + objId);
else if (document.all) return eval(“document.all.” + objId);
else return eval(“document.” + objId);

/*copy this in body */

<font> Maximum Number of characters for this text box is 255.<br>
<textarea onKeyPress=”return taLimit(this)” onKeyUp=”return taCount(this,’myCounter’)” name=”Description” rows=7 wrap=”physical” cols=40>
You have <B><SPAN id=myCounter>255</SPAN></B> characters remaining
for your description…</font>

Entry filed under: Javascript. Tags: .

Sachin silences the critics [ especially sanjay manjrekar] Ricky Pointing : CB- Series song [ taare zameen par]

7 Comments Add your own

  • 1. Jaffer Haider  |  March 4, 2008 at 4:12 pm

    Hmm … will this handle the case if a user pastes text into the textarea?

  • 2. Jane Crone  |  May 22, 2008 at 3:14 pm


  • 3. sdsd  |  March 10, 2009 at 6:43 am


  • 4. xx  |  October 27, 2009 at 1:28 pm


  • 5. Anoop  |  September 29, 2011 at 1:00 pm


    • 6. Laura  |  November 4, 2011 at 6:45 pm

      Land na chalat ba ukada baith ke

  • 7. talib  |  November 17, 2011 at 5:03 am

    ddxxzvv vfvvvv


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

Flickr Photos

Affenschlucht in Winterthur

high surface tension...

The New York Times Building

More Photos

Blog Stats

  • 690,663 hits


Get every new post delivered to your Inbox.

Join 38 other followers

%d bloggers like this: