Jump to content

Checking TEXTAREA amount of characters


gtrufitt

Recommended Posts

Hi, this script is meant to make sure a user cannot enter more than 42 characters into a textarea, but it is not working, any help as to why would be great!

 

<script language="JavaScript" type="text/javascript">
<!--
  function maxlength(element, maxvalue)
     
     var q = eval("document.pooh."+element+".value.length");
     var r = q - maxvalue;
     var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. Please abbreviate "+
       "your text by at least "+r+" characters";
     if (q > maxvalue) alert(msg);
    
//-->
</script>
  <p> 
      <label for name="about">About: </label>
      <textarea cols="30" rows="5" name="about" maxsize="42" onchange="maxlength('about', 42)">I don't want anyone to know about me!</textarea>
    </p>

 

Thanks,

 

Gareth

Link to comment
Share on other sites

Seriously?

 

 var q = eval("document.pooh."+element+".value.length");

 

eval() is evil.

 

 var q = document.pooh[element].value.length;

 

And since it's in a form, you should be able to navigate the hierarchy from the form object, no need to go back to document, just takes longer.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.