By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

max Limit on textarea

P: 15
How to put a max limit in the amount of characters entered into the textarea? I tried with MAXLENGTH attribute, but it didnot work.
Any help will be rally appreciated.
Thanks in advance.
Oct 13 '06 #1
Share this Question
Share on Google+
7 Replies

P: 76
I don't think there's a way to do it with the straight HTML, I think you need to use a javascript function. Something akin to...

<script language="Javascript">
function tooLong(strTest,maxLength)
if(strTest.value.length > maxLength)
strTest.value = strTest.value.substr(0,50);

<textarea name="myText" onChange="tooLong(this,50)"></textarea>

Or something like that. You could also add something like "Characters Remaining".
Oct 13 '06 #2

Expert 5K+
P: 7,435
<textarea cols="number of columns">
This should be done with css but I don't recall how. I'll look into it.
Oct 13 '06 #3

Expert 5K+
P: 7,435
As it turns out, there isn't one.
Oct 13 '06 #4

P: 76
<textarea cols="number of columns">
This should be done with css but I don't recall how. I'll look into it.
That limits the visible size of the textarea but doesn't control how many characters can be entered at all. You can cause a textarea to scroll for a million years if you wanted to... and despite the fact that you can add a maxlength attribute to the textarea not all browsers recognize it so it's glitchy at best. My solution won't even really work if they have javascript turned off.
Oct 13 '06 #5

P: 8
<input name="textfield" type="text" value="" size="25" maxlength="20">

Try this, think this is wht you mean. (you will need to change the max length to however many characters you want to allow.
Oct 13 '06 #6

P: 29
Here's another script which also gives the user a little counter to see how many characters they have left to use - may come in handy :-)

Javascript Source
Oct 13 '06 #7

P: 15
My problem is fixed.Thanks a lot to everyone.
Oct 16 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.