Results 1 to 4 of 4

Thread: maxlength property

  1. #1

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236

    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?

  2. #2
    scoutt
    Guest
    do you mean how to set one for a textbox thru javascript?

  3. #3

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    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?

  4. #4
    scoutt
    Guest
    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
  •  



Click Here to Expand Forum to Full Width