maxlength for textarea

stefborg
stefborg used Ask the Experts™
on
i'm using html+vbscript.in my textarea i need not to allow more then 100 characters. Can you help me?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You're right, there is no size attribute for some stupid reason.  I've made a JavaScript here that should limit the amount of text that one may enter in a textfield.


<html>
<head>
<script language="javascript">
var i = 1;
var olData;
  function chcklngth(e)
  {
    var charCode = (navigator.appName=="Netscape")?e.which:e.keyCode;
    i++;
    if ( i > 10)
    {
      window.document.frm.ta1.value=olData;
      i=10;
    }
    if ( charCode == 8)
    {
      i-=2;
    }
    olData=window.document.frm.ta1.value;
  }
</script>
</head>
  <body>
    <form name=frm>
      <textarea name=ta1 rows=10 cols=50 onkeydown="javascript:chcklngth(event);"></textarea>
    </form>
  </body>
</html>

Hope this got to you in time!

Commented:
replace all occurences of 10 with 100 in the head of the page.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for 8_digits

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Venabili
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial