limiting textarea input
Is there a way to limit the lenght (characters) for a textarea form element? 'Maxlength' only seems to work for input tags such as text.
Is there a way to limit the lenght (characters) for a textarea form element? 'Maxlength' only seems to work for input tags such as text.
fairhousing posted this at 19:39 — 11th December 2000.
They have: 1,587 posts
Joined: Mar 1999
um, u've confused me. ur asking how to limit the characters for a form text area. then u go on to talk about maxlength, hello. maxlength is it, i'm confused, hehe.
Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?
Andrew posted this at 19:54 — 11th December 2000.
They have: 16 posts
Joined: Jan 2000
The following form tags are for different form elements:
The tag creates a scrolling text box. 'maxlength' does not work with this tag.
My question is, how can I limit input into a field the same way 'maxlength' does with a tag.
Suzanne posted this at 22:18 — 11th December 2000.
She has: 5,507 posts
Joined: Feb 2000
maxlength="235" or whatever limits the amount of characters that can be entered into the form field.
In order to limit the size of the form field, you use size="10" where 10 is whatever size works for your needs.
Please keep in mind that Netscape will make the field sizes different than IE will, so test in both.
Suzanne
Mark Hensler posted this at 04:40 — 12th December 2000.
He has: 4,048 posts
Joined: Aug 2000
size=10 is only for
rows=20 cols=4 is for
as for limiting characters... let me get my book..
there is no property for that.
BUT, if your adventurous, you could write a javascript for this using the onKeyPress or onKeyDown.
count the number of characters
once over the limit, alert() or something.
Mark Hensler
If there is no answer on Google, then there is no question.
Suzanne posted this at 17:20 — 12th December 2000.
She has: 5,507 posts
Joined: Feb 2000
doh! Max is right, I was responding to the form element.
Max is also right that the element has no natural limitation attributes other than size (rows, cols), so if you want to limit characters, either use JavaScript, trim using your form parser in whatever language you script in (ASP, Perl, et cetera), or use an element instead.
Suzanne
ianrules posted this at 22:49 — 13th December 2000.
They have: 74 posts
Joined: Sep 2000
Andrew,
I gpot this code from The Javascript Source.
In this case the maxlength is 125.
You can of course change that to whatever you want,
just follow the directions:
<!-- TWO STEPS TO INSTALL LIMIT TEXTAREA:
1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<script LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->
<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: <a href="http://www.shiningstar.net" class="bb-url">http://www.shiningstar.net</a> -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! <a href="http://javascript.internet.com" class="bb-url">http://javascript.internet.com</a> -->
<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<!-- textCounter() parameters are: text field, the count field, max length -->
<center>
<form name=myform action="YOUR-SCRIPT.CGI">
<font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 125 characters. )<br>
<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="125"> characters left</font>
</form>
</center>
<p><center>
<font face="arial, helvetica" SIZE="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.37 KB -->
Hope this helps.
Ian,
hehe
Mark Hensler posted this at 02:50 — 14th December 2000.
He has: 4,048 posts
Joined: Aug 2000
thanks!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.