|
-
May 19th, 2004, 06:26 AM
#1
Thread Starter
Addicted Member
Limit the character length of a <textarea> field? [resolved]
How can I limit the length, in characters, of a <textarea> field. I have tried the MAXLENGTH= property, but it seems to have no effect.
Thanks
Jez
Last edited by Jez1; May 19th, 2004 at 09:48 AM.
-
May 19th, 2004, 07:24 AM
#2
In the onKeyDown event, call a function that checks the length of the value of the textarea.
Code:
//let's suppose, maxlimit = 100
if (textareaname.value.length > maxlimit)
textareaname.value = textareaname.value.substring(0, maxlimit);
HTH
-
May 19th, 2004, 07:33 AM
#3
Frenzied Member
Yeah, I was trying this:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function doIt(_obj) {
/*
Couldnd't get this working:
if (the_key_pressed_in_ascii == 8) //Backspace
{
return true
}
*/
if (_obj.value.length > 15)
{
return false
}
}
</script>
</head>
<body>
<textarea onKeyPress="return doIt(this)"></textarea>
</body>
</html>
but your code is robably better.
Have I helped you? Please Rate my posts. 
-
May 19th, 2004, 07:41 AM
#4
Thread Starter
Addicted Member
I'm guessing that's Javascript.
Could you provide a simple explaination of how to put that code into a function and how to call it on the onKeyDown event please?
Javascript is confusing to me
-
May 19th, 2004, 08:55 AM
#5
Frenzied Member
using menhaks code:
Code:
<script type="text/javascript">
function doIt(_obj) {
//let's suppose, maxlimit = 100
maxlimit = 100
if (_obj.value.length > maxlimit)
_obj.value = _obj.value.substring(0, maxlimit);
}
</script>
<textarea onKeyDown="return doIt(this)"></textarea>
Have I helped you? Please Rate my posts. 
-
May 19th, 2004, 09:48 AM
#6
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|