|
-
May 8th, 2002, 10:15 AM
#1
Thread Starter
Addicted Member
maxlength on textarea?
Anybody know if you can set a maxlength on a textarea? I tried just slapping maxlength='150' in it but it didn't a work.
-
May 8th, 2002, 10:58 AM
#2
Addicted Member
I really like this approach to the problem:
http://www.supermegaphone.com/message.htm
For this textarea, when you type, you see a field that counts down the number of characters remaining. With innerHTML, you wouldn't even have to have the number being displayed in a field, you could just place the number-of-characters-remaining right next to the textarea.
cudabean
-
May 8th, 2002, 11:00 AM
#3
Fanatic Member
Theres no attribute for this, you'll have to use a client side script to do it
Code:
<html>
<head>
<title>Validating Text Area value</title>
<script language="JavaScript">
var txtLimit = 10
function limitChar(){
var txtAreaString = document.forms['formName'].txtAreaName.value
if (txtAreaString.length > txtLimit){
alert("Your entry is " + txtAreaString.length +
"characters long." +
" Limit the text area to " + txtLimit +
" characters. Please try again.")
document.forms['formName'].txtAreaName.focus()
return false
} return true
}
</script>
</head>
<body>
FormFieldName: (Character Limit:
<script language="JavaScript">
document.write(txtLimit)
</script>
)
<form name="formName" onSubmit="return limitChar()">
<textarea name="txtAreaName" cols="50" rows="10"></textarea>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</form>
</body>
</html>
-
May 8th, 2002, 11:39 AM
#4
PowerPoster
I like the countdown thing too, here is a very simple version
Code:
<html>
<head>
<SCRIPT Language = "JavaScript">
function UpdateCharCount() {
intChars = 255 - document.form1.Comments.value.length;
document.form1.Remaining.value = intChars;
}
</SCRIPT>
</head>
<body>
<form name="form1" action="" method="post">
<textarea name="Comments" rows="3" cols="20" onKeyUp="javascript:UpdateCharCount();"></textarea>
<br>
<input type="text" name="Remaining" value="255" size="3" maxlength="3" disabled>
</form>
</body>
</html>
Tested in IE6, NS6.2 and Opera 6
change 255 to whatever you want the limit to be
-
May 8th, 2002, 11:59 AM
#5
Thread Starter
Addicted Member
Great, thats what I needed. I'm surprised they dont have a property of the textarea for this already but cuttin and pastin script ain't too hard either. Thanks.
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
|