On Nov 16, 2004, at 1:59 AM, Garth Hapgood - Strickland wrote:
Unlike the input fields that use maxlength to define the number of character
allowed. Textarea doesnt seem to have that capability. I want to limit the
number of character to 255.
IS there any way of doing this without having to break my neck about it?
Garth
Garth,
This has to be done with JavaScript or some client-side scripting language. I use this exact thing for a textarea and it works rather well. I want to restrict the user to 255 characters, so here's what I do:
[code] -- in javascript --
<script type="text/javascript"><!-- function textCounter (field, countField, maxLimit) { if (field.value.length > maxLimit) field.value = field.value.substring(0, maxLimit); else countField.value = maxLimit - field.value.length; } //--></script>
-- in html --
<textarea name="comments" rows="10" cols="45" onkeydown="textCounter(this.form.comments, this.form.remainingLength, 255);" onkeyup="textCounter(this.form.comments, this.form.remainingLength, 255);"></textarea>
<br />Characters remaining: <input readonly type="text" name="remainingLength" size="5" maxlength="3" value="255" />
[/code]
The the input text box does is just keep a counter of how much characters they have remaining. It's only function is to indicate to the user how much they have left.
Hope that helps. ~Philip
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php