469,271 Members | 1,743 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

max Limit on textarea

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
7 24014
Arielle
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...

<html>
<head>
<script language="Javascript">
function tooLong(strTest,maxLength)
{
if(strTest.value.length > maxLength)
{
strTest.value = strTest.value.substr(0,50);
}
}
</script>
</head>
<body>

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

Or something like that. You could also add something like "Characters Remaining".
Oct 13 '06 #2
drhowarddrfine
7,435 Expert 4TB
<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
drhowarddrfine
7,435 Expert 4TB
As it turns out, there isn't one.
Oct 13 '06 #4
Arielle
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
<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
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
swarnap
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.

Similar topics

6 posts views Thread by Jay | last post: by
4 posts views Thread by Simon | last post: by
4 posts views Thread by wing | last post: by
5 posts views Thread by Jesper Rønn-Jensen | last post: by
7 posts views Thread by Dean Trower | last post: by
5 posts views Thread by JohnSouth | last post: by
3 posts views Thread by teser3 | last post: by
7 posts views Thread by =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.