|
-
Jan 17th, 2002, 09:08 AM
#1
Thread Starter
Addicted Member
maxlength property
Is there a Maxlength property that I can grab from a textbox using JavaScript? I know I can set it in the tag itself but is there a way to access it through JavaScript?
-
Jan 17th, 2002, 07:59 PM
#2
do you mean how to set one for a textbox thru javascript?
-
Jan 17th, 2002, 08:42 PM
#3
Thread Starter
Addicted Member
yeah, set one or just read one. I'm going through a loop that fills the textbox with spaces until the textfield reaches its match length (so that a textfield that has a maxlength of 8 characters must be 8 characters when the form is sent, even if the user only entered 3). Make sense?
-
Jan 18th, 2002, 02:33 PM
#4
well I don't know if this will help but here a piece of code that tells you how many characters you have left.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->
<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: http://www.shiningstar.net -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- 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>
<body>
<form name=form1>
<textarea name=content cols=70 rows=18 onKeyDown="textCounter(this.form.content,this.form.remLen,4000);" onKeyUp="textCounter(this.form.content,this.form.remLen,4000);" onFocus="textCounter(this.form.content,this.form.remLen,4000);"></textarea><br><br>
<input readonly type=text name=remLen size=2 maxlength=3 value="4000" style="border: 1px;"> characters left</font>
</form>
</body>
</html>
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
|